I don't think there is a noticable difference.
Considering what an easy function AbsoluteTiming
is, you might as well build your own version and see how it compares (remember to start a fresh kernel before evaluating):
SetAttributes[myAbsoluteTiming, HoldAll];
myAbsoluteTiming[calculation_] := Module[{startTime, deltaTime, result},
startTime = SessionTime[];
result = calculation;
deltaTime = SessionTime[] - startTime;
{deltaTime, result}
]
myAbsoluteTiming@Prime[10^11]
{7.042020, 2760727302517}
Let's compare that to the built-in function:
AbsoluteTiming@Prime[10^11]
{7.058939, 2760727302517}
Considering how little memory and computation time is used by myAbsoluteTiming
(just by looking at its code), I don't think there is any reason to assume that myAbsoluteTiming
slows you down, and the intenal implementation is most likely even faster. (If you're using it a million of times in a matter of seconds, then maybe you'll notice an impact on performance, but that's hardly a useful application of the function.)
"Well, maybe SessionTime
is slow ..." - nope:
AbsoluteTiming@Do[SessionTime[], {10^6}]
{3.665901, Null}
Concerning your follow-up question, what you want is basically the content of the Module
in the code for myAbsoluteTiming
given above: determine SessionTime
before and afterwards, calculate difference.
Utilities`ShowTime`
by Roman Maeder that I used whenever I wanted the timing information to be merely printed out as opposed to being part of the output. You might want to look into it, and perhaps modify the code so that it usesAbsoluteTiming[]
instead ofTiming[]
. $\endgroup$