开发者

output from AbsoluteTiming

This is just a curiosity - I don't have a re开发者_开发百科al question. The output of AbsoluteTiming has a definite pattern; can anyone confirm/explain ?

xxx = RandomReal[NormalDistribution[0, 1], 10^6];

Sin[#] & /@ xxx; // AbsoluteTiming
(* {0.0890089, Null} *)

Max[Exp[#] - 0.5, 0] & /@ xxx; // AbsoluteTiming
(* {0.1560156, Null} *)

$Version
8.0 for Microsoft Windows (64-bit) (February 23, 2011)


According to the Documentation, "AbsoluteTiming is always accurate down to a granularity of $TimeUnit seconds, but on many systems is much more accurate." So evaluating $TimeUnit probably can elucidate this issue.


Yep. Let´s check if the time quantum is consistent:

Differences@
 Round[10^5 Sort@
    Union[AbsoluteTiming[
         Sin[#] & /@ 
           RandomReal[NormalDistribution[0, 1], #];][[1]] & /@ 
      RandomInteger[10^6, 100]]]

(*
-> {1562, 1563, 1563, 1562, 1562, 1563, 1563, 1562, 1562, 1563, 1563, \
    1562, 1562, 1563, 1563, 1562, 1562}
*)

Edit

Better code

Differences@
 Sort@Union[
   Round[10^5 AbsoluteTiming[
         Sin[#] & /@ 
           RandomReal[NormalDistribution[0, 1], #];][[1]] & /@ 
     RandomInteger[10^6, 100]]]


Presumably your system's clock only has granularity to some fraction of a second that happens to produce a repeating decimal. I have never noticed this on my Macs.
It's cool, though.

EDIT
Now that I am home I can confirm this must be system-specific: here is my output from the code in belisarius's answer:

{56, 119, 28, 25, 33, 397, 35, 82, 185, 67, 41, 67, 218, 192, 115, \
28, 74, 16, 187, 222, 194, 8, 129, 399, 68, 75, 71, 34, 5, 37, 62, \
64, 137, 173, 24, 98, 135, 308, 63, 155, 208, 861, 22, 72, 72, 184, \
609, 564, 112, 1011, 118, 81, 158, 90, 351, 33, 35, 68, 10, 126, 39, \
194, 7, 108, 278, 75, 37, 214, 34, 166, 119, 10, 335, 141, 4, 988, \
90, 121, 71, 130, 117, 186, 33, 123, 111, 110, 57, 64, 213, 217, 210, \
204, 98, 247, 20, 1421, 28, 2003, 353}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜