MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Ron Knapp's time function

  • To: mathgroup at
  • Subject: [mg24612] Re: Ron Knapp's time function
  • From: Robert Knapp <rknapp at>
  • Date: Fri, 28 Jul 2000 17:23:48 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <8kjehf$>
  • Sender: owner-wri-mathgroup at

fkampas wrote:
> Does anybody have the Mathematica code
> for the generalized timing function that Ron
> Knapp presented at the last developer's
> conference?  It isn't given in his notebooks
> in the conference section on the Wolfram
> web site.

I tried posting this before, but it must have been lost:

There is a more complete archive of talk notebooks I have used on my
personal web page:

.... and therein you will find

which contains the function you seek.

The time function is also used and included in my most recent
Mathematica Journal article, which you can find pointers to through the
main Wolfram research site


Or simpler yet, here is the code

SetAttributes[time, HoldAll];

time[expr_] := 
  Block[{Second = 1}, Module[{t = First[Timing[expr]], tries = 1},
      While[t < 1., tries *= 2; t = First[Timing[Do[expr, {tries}];]]];
    ] ]

The intent of this function is to allow you to compare timings of
operations which may take only fractions of a second by using repetition
to smooth over the timing granularity.  It also suppresses the command
output which, for people like me who are forgetful, avoids accidental
huge outputs when comparing timings.

  • Prev by Date: Re: Simlifying Sqrt[x^2] type args.
  • Next by Date: interruptedWhile ADDENDUM
  • Previous by thread: Re: Ron Knapp's time function
  • Next by thread: Q: Replacing Symbols