What is CPU time?

The total time the CPU spent executing a program's instructions, excluding waits; with parallel execution it can exceed wall-clock time.

Field: Performance Analysis

Japanese name: CPU時間

CPU time vs. wall-clock time

Wall-clock time, also called elapsed or real time, is what a user waits from start to finish, including time spent waiting for disk, network or locks and time slices given to other programs. CPU time counts only the time a processor actually spent executing the program. On Unix-like systems the time command shows both: real is wall-clock time, while user and sys split CPU time into the program's own code and kernel work done on its behalf, such as system calls.

Reading the ratio

Comparing the two values shows where time goes. If wall-clock time is much larger than CPU time for a single-threaded program, it is mostly waiting, typically on I/O or locks, and a faster processor will help little. If CPU time is close to wall-clock time, the program is compute-bound. With several threads running in parallel, total CPU time can exceed wall-clock time: four threads each busy for 10 s give about 40 s of CPU time in about 10 s of elapsed time.

The CPU performance equation

In computer architecture, the CPU time of a program is written as instruction count × CPI (average clock cycles per instruction) × clock period, or equivalently instruction count × CPI ÷ clock frequency. The equation separates the contributions of the compiler and instruction set (instruction count), the microarchitecture (CPI) and the circuit technology (clock rate). It also shows why improving one factor at the expense of another, such as raising frequency while CPI worsens, may not make a program faster.

CPU time as a budget

Busy CPU time is not always useful work. A thread spinning on a lock that is held for a long time burns CPU time doing nothing, and on a single core it can even delay the lock holder until its time slice ends; long waits call for a mutex that sleeps. In real-time and automotive systems, CPU time is allocated and monitored per task, and temporal partitioning ensures a misbehaving lower-criticality task cannot consume the execution time that safety-critical software needs.

Try it: questions about CPU time

What is the difference between wall-clock time and CPU time?

  1. AWall-clock time is the actual elapsed time from start to finish, including I/O waits; CPU time counts only time the CPU spent executing the program
  2. BWall-clock time and CPU time are always equal
  3. CCPU time is time measured on a wall clock
Show answer and explanation

Answer: A. Wall-clock time is the actual elapsed time from start to finish, including I/O waits; CPU time counts only time the CPU spent executing the program

Wall-clock time is what the user actually waits, including time spent waiting for disk or network and time yielded to other programs. CPU time is the total time the CPU spent executing the program's instructions. If wall-clock time is much longer than CPU time, a lot of time is spent waiting. Conversely, with multiple threads running in parallel, total CPU time can exceed wall-clock time.

FAQ

Why is CPU time greater than real time?

The program used several threads or processes running simultaneously on different cores, and CPU time adds up the time on all of them. Four fully busy threads, for example, accumulate roughly four seconds of CPU time per second of elapsed time.

What do real, user and sys mean in the time command?

Real is elapsed wall-clock time, user is CPU time spent in the program's own code, and sys is CPU time the kernel spent on its behalf, such as handling system calls.

Does CPU time include waiting for I/O?

No. While a program waits for disk or network it is not executing, so that time appears in wall-clock time but not in CPU time.

Questions that mention CPU time (4)

CPU time appears in 5 practice questions across 5 topics, including Performance Analysis, Automotive Semiconductors and Functional Safety, CPUs and architecture.

  1. When the functions of multiple ECUs are integrated into a single high-performance SoC and software of different ASILs runs together, which is required?
  2. Which CPU mechanism temporarily suspends the current task to give priority to handling requests such as those from external devices?
  3. In which situation is a spinlock least suitable?
  4. Which correctly describes the realm introduced in Arm CCA (Confidential Compute Architecture)?

Books on Performance Analysis Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary