Message Boards Message Boards

0
|
5699 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Is this correct Timing behavior ?

Posted 10 years ago
I type this
Timing[Pause[1.0]]
and I get 0. for the time. I tried with all other possible expressions and the same holds. This seems to work in the OS X version we run at work.
5 Replies
The "quantum of time" is typically 16 mSec for Windows, but can change depending on what's loaded.
POSTED BY: Frank Kampas
If the computations takes less that $TimeUnit, it will round to zero. Does this return zero on your system:
First@Timing[PrimeQ[Range[10^7]]]
POSTED BY: Nasser M. Abbasi
Ok, whatever glitch happened with Timing, it is gone :-/ but I am still unable to use it in my program. See, what I attempt to do:
SetAttributes[MyTime, HoldAll];
MyTime[expression_, prefix_: "expression"] :=
  Block[{text = "Time for " <> prefix <> " is "}, Print["Starting"];
   Block[{aux2 = Timing[Evaluate[expression]]}, Print["Finished"];
    Print[text <> ToString[ aux2[[1]]*1000] <> "ms"]; aux2[[2]]]];
This always prints zero, no matter how long the computation in "expression" takes. Using AbsoluteTiming also does not work.
Timing[Pause[1.0]]
does not measure wall clock time, it measures CPU time spent in the kernel.  Pause[] does not use much CPU time in the kernel at all (nothing to compute, just makes an OS call), so you get zero CPU time.
Try
AbsoluteTiming[Pause[1.0]]
which returns
{1.000627, Null}
Which returns wall clock time elapsed:
 returning a list of the absolute number of seconds in real time that have elapsed
POSTED BY: Nasser M. Abbasi
I reckon it was an unfortunate example, but if I replace Pause[1.0] with an actual computation, as in the examples from http://reference.wolfram.com/mathematica/ref/Timing.html it also does not work.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract