Re: Re: Combined Set, SetDelayed
- To: mathgroup at smc.vnet.net
- Subject: [mg100851] Re: [mg100829] Re: Combined Set, SetDelayed
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Tue, 16 Jun 2009 21:51:20 -0400 (EDT)
- References: <h0vteh$6v2$1@smc.vnet.net> <h12gck$e8s$1@smc.vnet.net>
Hi Helen, my guess is that the point was that this kind of timings are clearly unrealistic and should not be taken literally. All they mean is that the time needed for a given operation is really very small, smaller than Mathematica can reliably measure given a single run of the code. Run it many times and divide the total timing by the number of runs, and you will get a more sensible timing. Here is the function (or, more precisely, macro) that automates this process (it suppresses the result): SetAttributes[myTiming, HoldAll]; myTiming[code_] := Module[{z = 0, y = 0, timelim = 0.1, p, q, iterlist = 10^Range[0, 10], nm = If[ToExpression[StringTake[$Version, 1]] < 6, 2, 1]}, Catch[ If[(z = Nest[First, Timing[(y++; Do[code, {#}]);], nm]) > timelim, Throw[{z, y}] ] & /@ iterlist] /. {p_, q_} :> p/iterlist[[q]] ]; Then, for example: In[1] = Timing[Range[1000];] Out[1] = {4.19803*10^-16,Null} In[2] = myTiming[Range[1000]] Out[2] = 5.11*10^-6 Regards, Leonid On Mon, Jun 15, 2009 at 2:37 AM, Helen Read <hpr at together.net> wrote: > AES wrote: > > Helen Read <hpr at together.net> > > wrote: > > > >> 0.811 seconds. The second version, using the function that remembers > >> values, took only 1.87003*10^-15 seconds. > > > > The frequency of visible light is around 3*10^14 Hz, so that's around > > one period of a visible light wave. Is there maybe a typo here? > > No, no typo. Not sure what your point is. > > -- > Helen Read > University of Vermont > >