Is there any way to run a C++ program slower by changing any OS parameters in Linux? In this way I would like to simulate what will happen if that particular program happens to run on a real slower machine.
In other words, a faster machine should behave as a slower machine to that particular program.
nice
(and/or renice
). You can also do it programmatically using nice()
system call. This will not slow down the execution speed per se, but will make Linux scheduler allocate less (and possibly shorter) execution time frames, preempt more often, etc. See Process Scheduling (Chapter 10) of Understanding the Linux Kernel for more details on scheduling.cpufreq-set
command.sched_yield()
, which will yield quantum to other processes, in performance critical parts of your program (requires code change).malloc()
, free()
, clock_gettime()
etc. using LD_PRELOAD, and do some silly stuff like burn a few million CPU cycles with rep; hop;
, insert memory barriers etc. This will slow down the program for sure. (See this answer for an example of how to do some of this stuff).-O0
and enable assertions (i.e. -DDEBUG
).Hope it helps.