Wolfram Research

Function Repository Resource:

TimeMemoryUsed

Source Notebook

Return the time taken and the memory used by an operation

Contributed by: Sander Huisman

ResourceFunction["TimeMemoryUsed"][expr]

evaluates expr, returning a list of the absolute number of seconds in real time that have elapsed, the maximum number of bytes used and the result.

Details and Options

ResourceFunction["TimeMemoryUsed"] uses AbsoluteTiming and MaxMemoryUsed.

Examples

Basic Examples

Find the time taken and memory used in calculating 54:

In[1]:=
ResourceFunction["TimeMemoryUsed"][5^4]
Out[1]=

Scope

TimeMemoryUsed can contain a CompoundExpression:

In[2]:=
ResourceFunction["TimeMemoryUsed"][
 out = Table[
   FactorInteger[RandomInteger[{10^18, 10^20}]]
   ,
   {10}];
 out = Total /@ out;
 Total[out]
 ]
Out[2]=

Properties and Relations

TimeMemoryUsed combines AbsoluteTiming and MaxMemoryUsed:

In[3]:=
AbsoluteTiming[Plot[Sin[x], {x, 0, 2 Pi}]]
Out[3]=

Check MaxMemoryUsed:

In[4]:=
MaxMemoryUsed[Plot[Sin[x], {x, 0, 2 Pi}]]
Out[4]=

Combine both of them:

In[5]:=
ResourceFunction["TimeMemoryUsed"][Plot[Sin[x], {x, 0, 2 Pi}]]
Out[5]=

Resource History

Related Resources

License Information