1 Matching Annotations
  1. Dec 2023
    1. Measure Execution Time With time.process_time()

      The time.process_time() reports the time that the current process has been executed.

      The time begins or is zero when the current process is first created.

      Calculated as the sum of the system time and the user time:

      process time = user time + system time

      System time is time that the CPU is spent executing system calls for the kernel (e.g. the operating system)

      User time is time spent by the CPU executing calls in the program (e.g. your code).

      When a program loops through an array, it is accumulating user CPU time. Conversely, when a program executes a system call such as exec or fork, it is accumulating system CPU time.

      The reported time does not include sleep time.

      This means if the process is blocked by a call to time.sleep() or perhaps is suspended by the operating system, then this time is not included in the reported time. This is called a “process-wide” time.

      As such, it only reports the time that the current process was executed since it was created by the operating system.