Timing

Timing[expr]

evaluates expr, and returns a list of the time in seconds used, together with the result obtained.

Details

  • Timing has attribute HoldAll.
  • Timing[expr;] will give {timing,Null}.
  • Timing is accurate only down to a granularity of at least $TimeUnit seconds.
  • Timing includes only CPU time spent in the Wolfram Language kernel. It does not include time spent in external processes connected via WSTP or otherwise. Nor does it include time spent in the Wolfram System front end.
  • Timing[expr] includes only time spent in the evaluation of expr, and not, for example, in the formatting or printing of the result.
  • On certain computer systems with multiple CPUs, the Wolfram Language kernel may sometimes spawn additional threads on different CPUs. On some operating systems, Timing may ignore these additional threads. On other operating systems, it may give the total time spent in all threads, which may exceed the result from AbsoluteTiming.
  • Timing[expr] may give different results on different occasions within a session. A typical reason is the use of internal system caches, which can be cleared with ClearSystemCache.

Examples

Basic Examples  (3)

Timing for a computation:

Compare timings for doing a computation different ways:

Suppress output to check the timing when the results are very large:

Make a plot comparing times for computing an FFT of length n:

Wolfram Research (1988), Timing, Wolfram Language function, https://reference.wolfram.com/language/ref/Timing.html (updated 2003).

Text

Wolfram Research (1988), Timing, Wolfram Language function, https://reference.wolfram.com/language/ref/Timing.html (updated 2003).

CMS

Wolfram Language. 1988. "Timing." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/Timing.html.

APA

Wolfram Language. (1988). Timing. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Timing.html

BibTeX

@misc{reference.wolfram_2024_timing, author="Wolfram Research", title="{Timing}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/Timing.html}", note=[Accessed: 22-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_timing, organization={Wolfram Research}, title={Timing}, year={2003}, url={https://reference.wolfram.com/language/ref/Timing.html}, note=[Accessed: 22-December-2024 ]}