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 ResourceFunction["EchoTiming"]["label",body].

Details and Options

ResourceFunction["EchoTiming"] has the attribute HoldAll.

Examples

Basic Examples (3) 

Echo some expression:

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

Omitting 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 (1) 

EchoTiming reports total time used, not just CPU time:

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

Possible Issues (1) 

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

Version History

  • 1.0.0 – 12 April 2019

License Information