Wolfram Research

Function Repository Resource:

EchoTiming

Source Notebook

Print the timing for an evaluation and return the result

Contributed by: Taliesin Beynon (Wolfram Research)

ResourceFunction["EchoTiming"][body]

prints the time taken to evaluate body, and returns the result of the evaluation.

ResourceFunction["EchoTiming"]["label",body]

prints the time with a custom label.

ResourceFunction["EchoTiming"]["label"][body]

is equivalent to EchoTiming["label",body].

Details and Options

EchoTiming has the Attribute HoldAll.

Examples

Basic Examples

Echo some expression:

In[1]:=
ResourceFunction["EchoTiming"][Nest[f, x, 5]]
Out[1]=

Omit the output:

In[2]:=
ResourceFunction["EchoTiming"][Nest[f, x, 5];]

Add labels:

In[3]:=
ResourceFunction["EchoTiming"]["factoring", FactorInteger[2^256 - 1]]
Out[3]=
In[4]:=
ResourceFunction["EchoTiming"]["integrate 5 times"][
 Nest[Integrate[#, x] &, x, 5]]
Out[4]=

Properties and Relations

EchoTiming reports total time used, not just CPU time:

In[5]:=
ResourceFunction["EchoTiming"][t = 2 ; Pause[t]; t = t + 3]
Out[5]=

Possible Issues

Measures of time may differ:

In[6]:=
ResourceFunction["EchoTiming"][CountryData["Italy", "GDP"]]
Out[6]=
In[7]:=
Timing[CountryData["Italy", "GDP"]]
Out[7]=
In[8]:=
AbsoluteTiming[CountryData["Italy", "GDP"]]
Out[8]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information