I measure cpu time and wall time of sorting algorithms on linux. Im using getrusage
to measure a cpu time and clock_gettime CLOCK_MONOTONIC
to get a wall time. Althought I noticed that a cpu time is bigger than wall time - is that correct? I always thought that cpu time MUST be less than wall time. My example results:
3.000187 seconds [CPU]
3.000001 seconds [WALL]
If a computation requires two seconds of processor time, then two processors can (ideally) complete it in one second. Hence a two-processor system has two CPU seconds for every wall-clock second. Even if you do not use multi-threading explicitly in your process, a library you use or the operating system may use multiple processors to perform work for your process.
Additionally, some of the accounting is approximate. A system might track processor time in some small unit, say microseconds for the purpose of argument, and charge a process for a microsecond anytime the process receives at least half a microsecond of processor time. (Which should be a lesson to all the people who answer floating-point questions with recommendations to use integer arithmetic to avoid rounding errors. All discrete arithmetic can have rounding errors.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With