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

Find the time taken and memory used of calculating 54:

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

Scope (1) 

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 (3) 

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]=

Publisher

SHuisman

Version History

  • 1.0.0 – 09 January 2020

Related Resources

License Information