Duration is the amount of time it takes for a process to complete. For example, if you check the time, then go out for a walk, then return and see fifteen minutes have elapsed, the duration of your walk was fifteen minutes.

Computers contain special hardware to measure time, and operating systems include commands you can use to measure how long a program takes to run.

How computers measure time

In modern computers, time can be measured by different clocks.

  • How computers measure time.

  • How to time a process on your computer.

  • In Windows Command Prompt.

  • In Windows PowerShell.

  • In Linux.

  • Related information

  • In Windows Command Prompt.

  • In Windows PowerShell.

  • In Linux.

  • The RTC (real-time clock) uses a quartz crystal which vibrates at a constant frequency to keep track of “human time”: years, months, days, hours, minutes, and seconds. However, its frequency (32768 Hz) is too slow to measure fractions of time smaller than 1/32768 of a second. Modern CPUs can complete an operation much faster than this, so the RTC cannot accurately measure the duration of a computer process.

  • A PIT (programmable interval timer) is a hardware counter that triggers an interrupt when a certain count total is reached. A common PIT is the Intel 8253 integrated circuit, originally designed to be used with the Intel 8080 processor. It operates at a frequency of 1.193182 MHz. It is used as the system clock by many operating systems, including Windows and Linux.

  • A TSC (timestamp counter) is a 64-bit register on all modern x86 CPUs. It counts individual CPU clock cycles, and was first introduced with the Pentium line of Intel CPUs. At first, it was useful in providing a clock that could measure smaller fractions of time than an RTC or PIT. However, it requires that the CPU operate at a constant speed to obtain an accurate measurement. Newer CPUs can change frequency (such as entering a “turbo” mode to gain temporary speed boosts, or throttling down to a lower speed when idle to conserve power). So the TSC, while still useful for other purposes, is no longer reliable for measuring constant time.

  • The HPET (high precision event timer) is a hardware timer, developed jointly by Intel and Microsoft, which is available on computers manufactured after 2005. In the CPU chipset on the motherboard, the HPET is usually on the southbridge. It counts time in 64 bits at a minimum of 10 MHz, and employs three “comparator” counters (either 32-bit or 64-bit) to arrive at a highly precise time measurement. The HPET is used for many purposes in your computer, such as synchronizing the audio stream when playing a video.

The most accurate of these timing methods is the HPET.

How to time a process on your computer

There are various ways to find out how long a process takes to complete on your computer.

In Windows Command Prompt

In the Windows Command Prompt, there is no built-in way to time a command. However, there is at least one simple way to find out when your command started and stopped. You can create a batch file that uses the %time% environment variable. For instance, if you create a batch file called mytime.bat, and give it these lines:

@echo off set timestart=%time% %* echo Start : %timestart% echo Finish: %time%

The variable %time% is the current time, and %* is everything after the command name. So to time the dir command, for instance:

mytime dir c:\

Volume in drive C is Windows10 Volume Serial Number is 5CB6-BCD6 Directory of c:
[directory listing…] 28 File(s) 4,500,506 bytes 12 Dir(s) 23,807,946,752 bytes free Start : 19:31:18.87 Finish: 19:31:18.89

In Windows PowerShell

In Windows PowerShell, you can find out how long a program takes to run by starting it with the Measure-Command cmdlet. In general, it is used like this:

This method is not precise. It does not measure CPU time, only “wall clock” time. So, other programs running on your computer affect the times shown. Also, the duration must be calculated manually, by subtracting the “start” time from the “finish” time.

Measure-Command {command}

The command runs, but any output is not shown. Instead, the output displays information about how long it took for command to complete. For example:

Measure-Command {dir}

Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 14 Ticks : 142200 TotalDays : 1.64583333333333E-07 TotalHours : 3.95E-06 TotalMinutes : 0.000237 TotalSeconds : 0.01422 TotalMilliseconds : 14.22

In Linux

In Linux, you can prefix any shell command with the time command to measure its duration. For instance, the following command will find any files in or beneath the current directory that contain the word hope. Then, it will report how long it took to find them:

time find /home/myuser -iname ‘hope

/home/myuser/files/computer-hope.jpg /home/myuser/backup/hope-backup.zip real 0m0.298s user 0m0.164s sys 0m0.088s

Unlike Measure-Command, the Linux time displays all output from the command being timed. Then, it reports three times: user time (how much time the command actually spent running), sys time (how much time was spent by the kernel performing required system tasks), and real time (total time elapsed).

Hardware terms, Software terms

  • How to set or change a computer’s date and time.