Re: Timing in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg74753] Re: Timing in Mathematica
• From: "er" <erwann.rogard at gmail.com>
• Date: Wed, 4 Apr 2007 03:54:21 -0400 (EDT)
• References: <euqnqt\$8br\$1@smc.vnet.net><euslgn\$9k9\$1@smc.vnet.net>

```On Apr 3, 12:34 am, "dimitris" <dimmec... at yahoo.com> wrote:
> It is very easy.
>
> Let for example
>
> foo = {x^n, Cos[x], Log[x]/x, Log[Sin[x]^2]*Tan[x], BesselJ[n, x],
> (2*x)/((x + 1)*(x^3 + 3*x^2 + 2*x + 1))}
> {x^n, Cos[x], Log[x]/x, Log[Sin[x]^2]*Tan[x], BesselJ[n, x], (2*x)/((1
> + x)*(1 + 2*x + 3*x^2 + x^3))}
>
> Then
>
> InputForm[(Timing[Integrate[#1, x]] & ) /@ foo]
> {{0.031*Second, x^(1 + n)/(1 + n)}, {0.015999999999999986*Second,
> Sin[x]}, {0.*Second, Log[x]^2/2},
>   {0.9530000000000001*Second, Log[Sec[x/2]^2]^2 + 2*Log[Sec[x/
> 2]^2]*Log[(Cos[x]*Sec[x/2]^2)/2] +
>     Log[Sec[x/2]^2]*Log[Sin[x]^2] - 2*Log[Sec[x/2]^2]*Log[-1 + Tan[x/
> 2]^2] - Log[Sin[x]^2]*Log[-1 + Tan[x/2]^2] +
>     Log[Tan[x/2]^2]*Log[-1 + Tan[x/2]^2] + 2*PolyLog[2, Sec[x/2]^2/2]
> + PolyLog[2, Cos[x]*Sec[x/2]^2] +
>     PolyLog[2, -Tan[x/2]^2]}, {0.030999999999999917*Second, 2^(-1 -
> n)*x^(1 + n)*Gamma[(1 + n)/2]*
>     HypergeometricPFQRegularized[{(1 + n)/2}, {1 + n, (3 + n)/2}, -
> (x^2/4)]},
>   {0.016000000000000014*Second, 2*(-Log[1 + x] + RootSum[1 + 2*#1 +
> 3*#1^2 + #1^3 & ,
>       (Log[x - #1] + 2*Log[x - #1]*#1 + Log[x - #1]*#1^2)/(2 + 6*#1 +
> 3*#1^2) & ])}}
>
> Regards
> Dimitris
>
> =CF/=C7 amitsoni.1... at gmail.com =DD=E3=F1=E1=F8=E5:
>
> > 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

hi,

the code below increases the number of function calls until timing>0
and also makes repeated timing measurements until a timing budget is
used.

In[1]:=
doTimingConstrained[inptFun_(*typically random*),tMax_][testFun_]:=
While[
And[restT>0,
With[{ins=Table[inptFun[],{i,1,blockSize}]},
TimeConstrained[
deltaT=Timing[testFun/@ins;][[1]]/Second}],
restT]]=!=\$Aborted],
If[Developer`ZeroQ[deltaT],blockSize*=2 (*reason:\$TimeUnit*)];
restT-=deltaT;];

In[2]:=
inptFun=Array[Random[]&,{10,10}]&

In[29]:=
doTimingConstrained[inptFun,0.1][Inverse]

Out[29]=
\!\({{1, 0.004000999999999636`}, {1, 0.`}, {2, 0.`}, {4, 0.`}, {8,
0.`}, {16,
0.`}, {32, 0.008000999999999776`}, {32, 0.012000000000000363`},
{32,
0.00799999999999976`}, {32, 0.007999999999999608`}, {32,
3.3436794999452957`*^-16}, {32, 0.008001000000000182`}, {32,
0.008001000000000025`}, {32, 0.008000999999999873`}, {32,
0.008000999999999718`}, {32, 3.0574501264091225`*^-16}, {32,
1.5178830414797062`*^-16}, {32, 0.007999999999999998`}, {32,
0.007999999999999844`}, {32, 0.00799999999999969`}, {32,
4.172009959724221`*^-16}, {32, 2.632442874794805`*^-16}, {32,
0.008001000000000109`}}\)

```

• Prev by Date: Re: Simplification with Integers assumption
• Next by Date: Re: Finding unknown parameters using Mathematica
• Previous by thread: Re: Timing in Mathematica
• Next by thread: Re: Timing in Mathematica