How Other Processes Affect Measurements with time Command

benchmarkperformancetime

If I time a process using the time command, I get output for 'real', 'user', and 'sys'.

My understanding from this discussion is that 'real' is wall time, whereas 'user' and 'sys' are process time.

Does this imply that 'user' and 'sys' will be unaffected by other processes? In other words, if the computer is under heavy load or light load from other processes, it may take more time on the wall clock ('real') to finish my process. But my process may have only required 5 seconds of running time, even though it was spread out over 20 seconds of real-world time.

Am I guaranteed that I'll be told '5 seconds user time' regardless of whatever else the system is doing?

Best Answer

No. Process/context switches aren't free.

How much other processes running will slow yours down is very system-dependent, but it consists of things like:

  • Every time a processor switches to a different address space (including process), then the MMU cache must be flushed. And probably the processor L1 caches. And maybe the L2 and L3 caches. This will slow down memory access right after your process is resumed (and this counts against your "user" time).

  • On a SMP (or multi-core) box, if two processes are trying to access the same parts of (physical) RAM, the processors must cooperate. This takes time. It is often done at a architecture level, below even the OS. This will count against your user or sys time, depending on when it hit.

  • Quick kernel locking (that doesn't actually schedule another process) will count against your sys time. This is similar to the point above.

  • on NUMA boxes, you may get moved to a different node. Memory access may now be cross-domain, and thus slower

  • other processes may influence power management decisions. For example, pegging more cores will reduce Intel Turbo Boost speeds, to keep the processor package inside its electrical & thermal specs. Even without turbo boost, the processor may be slowed due to excess heat. It can work the other way too—more load may cause the CPU speed governor to increase the CPU speed.

There are other shared resources on a system; if waiting for them doesn't actually involve your process sleeping, then it'll get counted against your user or sys time.

Related Question