Finding CPU time of more than one expressions

I want to find the computational time (CPU time) of my code.

When I use TimeUsed or Timing commands they give the CPU time of only one cell. But my program contain many expressions including loops, is there any way to find CPU time of more than one expressions?

Or is there any way to find the starting time of computation and ending time of computation.

Thanks blochwave for giving me a detailed answer, but I have already used all these methods and none of them has worked well, it is clearly written in mathematica "get help" file that the Timing and AbsoluteTiming calculates the time of ONE expression only , and when I use in one cell with your suggestion. it gives me time of my code 0.0156 and using on all other codes the result is same 0.0156, no change with other codes, it means it is giving the time of only one expression as i have all my codes have first expression same but their other are different and complicated expressions, I have also used ClearSystemCache so to avoid the the memorized values but getting same result.

• There should be a better way but I assume that starttime = AbsoluteTime[];...;endtime = AbsoluteTime[]; endtime-starttime would give an idea.
– Öskå
Commented Jan 7, 2015 at 12:11
• If everything is in a single cell, you can do AbsoluteTiming[expr1;expr2;expr3;] Commented Jan 7, 2015 at 12:21
• Have you seen this? (7768). I found that I (sometimes?) need to copy my entire code and wrap it in RuntimeToolsProfile for this to work properly, but it should let you know where the time is being spent if you get it working. Commented Jan 9, 2015 at 9:15
• You might need to clarify - "calculates the time of ONE expression only" - reference.wolfram.com/language/ref/AbsoluteTiming.html says that, to me, it calculates the time of anything within the brackets. Look at the first example - it's doing 3 different things and timing the whole thing... Commented Jan 9, 2015 at 11:44

This is one solution, encapsulating all your expressions in the form: AbsoluteTiming[expr1;expr2;].

AbsoluteTiming[
a = Range[123456];
Pause[1];
Total[a]
]

(* 1.01503 seconds, returns 7620753696 *)

Needs["GeneralUtilities"]
AccurateTiming[
a = Range[123456];
Pause[1];
Total[a]
]

(* 1.001246 seconds *)


Also works fine with Timing[] for just the CPU time.

Timing[
a = Range[123456];
Pause[1];
Total[a]
]

(* 0.016002 seconds, returns 7620753696 *)