Timing¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Timing[expr] evaluates expr, and returns a list of the time in seconds used, together with the result obtained.
Notes
Timing reports CPU time summed over threads; use AbsoluteTiming to measure elapsed time.Examples (3)¶
Every input below was run against the current Mathilda build and its output recorded.
Applications (3)¶
In[1]:= Timing[Sum[i, {i, 1000}]]
Out[1]= {0.000244, 500500}
In[2]:= Timing[Sum[i, {i, 1, 1000000}]][[2]]
Out[2]= 500000500000
In[3]:= Timing[D[Tan[x]^10, x]][[2]]
Out[3]= 10 Sec[x]^2 Tan[x]^9
Implementation notes¶
builtin_timing brackets a single evaluate(arg) call with clock() (CPU time, CLOCKS_PER_SEC) and returns {seconds, result} as a two-element List, where seconds is (end - start)/CLOCKS_PER_SEC as an EXPR_REAL. It measures processor time, not wall-clock, and times a single evaluation only. (Note: the argument is evaluated explicitly inside the builtin; Timing is not given Hold attributes here.)
HoldAll,Protected,SequenceHold.- Returns
{timing, result}. - Includes only CPU time spent evaluating the expression, summed over threads.
A threaded NDArray path or a BLAS call is therefore over-reported by roughly the
core count — use
AbsoluteTimingto measure how long something actually took.
Attributes: HoldAll, Protected, SequenceHold.
References¶
See also: HoldAll, SequenceHold, AbsoluteTiming
- Source:
src/datetime.c - Specification:
docs/spec/builtins/time-and-date.md - Tests:
tests/test_datetime.c - Tests:
tests/test_ludecomposition_machine.c - Tests:
tests/test_parse.c
Notes & additional examples¶
Notes¶
Timing returns {seconds, result}. The first element is the CPU time spent and varies between runs and machines; only the second element (the computed result) is reproducible.