How to Express Computer Time Units with siunitx
At a glance
- 1. Use SI time units
Format seconds and their prefixes with siunitx, such as milliseconds, microseconds, and nanoseconds.
- 2. Declare custom units
Define names such as cycle or tick with DeclareSIUnit when they are not ordinary SI units.
- 3. Relate cycles to time
Use the clock frequency to convert a cycle count into elapsed time.
- 4. Check the meaning
A CPU cycle is a count, not a fixed duration; its time depends on the clock frequency.
For elapsed computer time, use siunitx’s built-in \second unit with an SI prefix: for example, \qty{12.5}{\milli\second} or \qty{80}{\nano\second}. If you need to report a count of processor cycles or timer ticks, define a custom unit so siunitx can format it consistently. Keep the distinction clear: a cycle count is not itself a duration, because the duration of a cycle depends on the clock frequency.
Use built-in units for durations
The second is the SI unit of time. In siunitx, prefixes are applied as unit commands before \second:
| Duration | siunitx unit expression |
|---|---|
| seconds | \second |
| milliseconds | \milli\second |
| microseconds | \micro\second |
| nanoseconds | \nano\second |
| picoseconds | \pico\second |
With siunitx version 3, use \qty for a number and its unit:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
The operation took \qty{12.5}{\milli\second}.
A memory access took \qty{80}{\nano\second}.
\end{document}
The package handles the spacing and unit typography. Avoid typing a unit as plain text after the number, such as 12.5 ms, when you want consistent formatting and number handling.
Define cycles or ticks as custom units
A processor cycle, timer tick, or jiffy may be useful to report as a count, but these are not SI units of time. Declare a unit command in the preamble:
\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit{\cycle}{cycle}
\DeclareSIUnit{\tick}{tick}
\begin{document}
The task used \qty{2400}{\cycle}.
The timer advanced by \qty{16}{\tick}.
\end{document}
Here, \DeclareSIUnit{\cycle}{cycle} creates \cycle for use in siunitx unit expressions. The printed words are labels for counts, not evidence that the count has a universal duration. If your field uses a particular abbreviation or symbol, declare that form instead and make its meaning clear in the surrounding text.
For siunitx version 2, the corresponding number-and-unit command is \SI{...}{...} rather than version 3’s \qty{...}{...}. The unit declarations and the distinction between a count and a duration are the same in principle. Check the installed package manual if you are maintaining a document that must work across package versions.
Convert cycles to elapsed time
If a clock runs at frequency cycles per second, then one cycle lasts seconds. A count of cycles therefore corresponds to
For example, suppose a processor runs at and a task takes 12,800 cycles. Since cycles per second,
You could report both the measured count and the derived time:
\qty{12800}{\cycle}, corresponding to \qty{4.0}{\micro\second}
The conversion assumes the stated frequency applies throughout the measurement. Modern processors may change clock frequency, and a reported cycle count may also depend on what the measurement tool counts. State the relevant conditions when those details matter.
Common mistakes
- Treating cycles as a fixed time unit. A cycle’s duration changes with clock frequency. A cycle count alone does not determine elapsed seconds.
- Using a time unit for a count. If the result is a number of cycles, label it as cycles; do not call it seconds unless you have converted it.
- Adding an SI prefix without defining its meaning. Prefixes such as milli-, micro-, and nano- have standard meanings with seconds. Computer-specific labels such as “tick” may have project- or system-specific definitions.
- Mixing up elapsed time and clock time. Elapsed time is a duration, such as 2.5 seconds. A time of day is a clock reading and needs different formatting and interpretation.
- Using the wrong siunitx command for the installed version. Version 3 uses
\qty; older documents commonly use\SI.
If the value is an elapsed duration, prefer a standard SI time unit. If it is a count of machine events, define and label that count explicitly, then show a conversion only when its assumptions are known.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.