Re: Timing in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg74739] Re: Timing in Mathematica
- From: "Szabolcs" <szhorvat at gmail.com>
- Date: Tue, 3 Apr 2007 00:26:54 -0400 (EDT)
- References: <euqnqt$8br$1@smc.vnet.net>
amitsoni.1984 at gmail.com =EDrta: > Hi, > > I am using Timing[.......] to calculate the time taken by an > expression in Mathematica. But it is not showing values below 0.01 > seconds. For values below 0.01s it just shows 0. Second > > Is it possible to get the value of time lower than 0.01s by somehow > lowering the least count. I am using Mathematica 5.2 on Windows. I was > getting lower values of time on Mathematica(5.2) on a Linux computer. > > Thank you, > Amit After doing some experimentation, I found that on my system AbsoluteTiming returns integer multiples of 0.015625 seconds. Timing returns the same values, but rounded to $TimeValue of 0.001. (Mathematica 5.2 on WinXP SP2) But you still shouldn't assume that timings are precise to 0.015625. For some reason, when I record several timing values with Table, the first one is always larger then the rest (significantly larger for short times). Here are two examples with very short timings: Table[First@ AbsoluteTiming[Do[NSum[i,{i,1,1000}],{1000}]]/Second,{100}]/ 0=2E015625 {36.,25.,26.,27.,29.,29.,28.,28.,27.,27.,26.,26.,26.,26.,25.,26.,25.,26.,26= .,\ 25.,26.,25.,26.,25.,26.,28.,25.,27.,26.,27.,26.,25.,27.,26.,26.,25.,26.,27.= ,\ 26.,26.,25.,26.,27.,25.,26.,25.,25.,28.,26.,26.,28.,25.,26.,25.,27.,26.,26.= ,\ 26.,26.,26.,25.,25.,26.,26.,29.,25.,26.,25.,25.,26.,25.,26.,25.,25.,26.,27.= ,\ 25.,26.,25.,26.,25.,25.,26.,25.,25.,26.,25.,25.,26.,25.,25.,26.,25.,26.,25.= ,\ 25.,25.,26.,25.,26.} Table[First@ AbsoluteTiming[Do[NSum[i,{i,1,1000}],{100}]]/Second,{100}]/ 0=2E015625 {6.,6.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.= ,3.\ , 3=2E,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,3.,2= .,3.\ , 2=2E,3.,2.,3.,2.,3.,2.,3.,2.,3.,3.,2.,3.,2.,3.,2.,3.,3.,2.,3.,2.,3.,2.,3.,2= .,3.\ ,3.,2.,3.,2.,3.,2.,3.,2.,3.,2.,3.,3.,2.,3.,2.,3.,3.,2.,3.,2.,3.,2.} Other calculations inside Do[] or using Timing instead of AbsoluteTiming give similar results. I hope that this will persuade you not try to measure very short execution times.