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.000113, 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
Performance¶
Against other systems, from the benchmark suite (same input, results cross-checked for agreement):
| case | Mathilda | Wolfram | Python |
|---|---|---|---|
| Interpolation evaluate, 20000 points | 18.9 s | 18.1 s | 0.073 s |
| Interpolation over 10^5 array | 1.26 s | 4.57 s | 4.44 s |
| Interpolation build, 2000 knots | 0.013 s | 0.761 s | 0.092 s |
| Interpolation order 1 (linear) build | -- | 0.764 s | 0.014 s |
| ListInterpolation 2-D 60x60 | -- | 0.823 s | 1.02 s |
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_meijerg.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.