Wolfram Research

Function Repository Resource:

EvaluationTiming

Source Notebook

Get a full timing report for functions evaluated during an evaluation

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["EvaluationTiming"][eval]

captures timing information for functions evaluated in eval.

ResourceFunction["EvaluationTiming"][eval,contexts]

captures timing information for functions in contexts.

Examples

Basic Examples

Retrieve the ResourceFunction:

In[1]:=
ResourceFunction["EvaluationTiming"]
Out[1]=

Get timing data for functions used in an evaluation:

In[2]:=
f[x_] := (Pause[.25]; g[x]);
g[x_] := (Pause[.5]; x + 1);
data = ResourceFunction["EvaluationTiming"][f /@ Range[5]]
Out[4]=

View the timing data as a Dataset:

In[5]:=
Dataset[data]
Out[5]=

Get the evaluation result:

In[6]:=
data["Result"]
Out[6]=

Scope

Track the timing of functions in specific contexts:

In[7]:=
data = ResourceFunction["EvaluationTiming"][
  CloudDeploy[FormFunction[{"x" -> "Integer"}, #x! &]],
  "CloudObject`" | "CURLLink`" | "URLUtilities`" ~~ ___
  ]
Out[7]=

Get the evaluation result:

In[8]:=
data["Result"]
Out[8]=

View the timing data (function names are color-coded by context):

In[9]:=
data["Summary"]
Out[9]=

View a BarChart:

In[10]:=
BarChart[data, ImageSize -> 500, ScalingFunctions -> "Log"]
Out[10]=

View a PieChart:

In[11]:=
PieChart[data, ImageSize -> 500]
Out[11]=

View the top 5 functions that are used the most times:

In[12]:=
data[{"Summary", 5}]
Out[12]=

Use a different key for sorting:

In[13]:=
data[{"Summary", 5, "Total"}]
Out[13]=

View a list of available properties:

In[14]:=
data["Properties"]
Out[14]=

Get the full data:

In[15]:=
data["ProfilingData"]
Out[15]=

Possible Issues

Without explicitly giving a context pattern, only functions in the current $Context will be tracked:

In[16]:=
MyContext`wait[] := Pause[1];
g[x_] := 2 x;
f[x_] := (MyContext`wait[]; g[x + 1]);
ResourceFunction["EvaluationTiming"][f[5]]["Summary"]
Out[19]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information