[Tutor] Uniques values in a list

Raymond Hettinger python@rcn.com
Sun, 17 Mar 2002 15:50:56 -0500


While we're building a test bench, I have a couple of
additions.  Do a full garbage collection just before the
timing starts -- this will reduce distortions due to gc.
Also, I would use xrange so that we don't eat-up
a meg of memory (100000 iters * (4 bytes per int + 4 bytes
per pointer to the int) ) before the function starts running.
At the end, print an excerpt of the results and its length.
That way you'll have some small assurance that the
function is really doing what it's supposed to.

Raymond


----- Original Message -----
From: "Sean 'Shaleh' Perry" <shalehperry@attbi.com>
To: "Alexandre Ratti" <alex@gabuzomeu.net>
Cc: <tutor@python.org>
Sent: Sunday, March 17, 2002 2:16 PM
Subject: Re: [Tutor] Uniques values in a list


>
import gc

> def benchmark(func, iters=100000):
       r = None
       gc.collect()
>     start = time.time()
>     for i in range(iters):
       # use xrange here instead of range
>         r = func(list1, list2)
>     end = time.time()
>     print "%d iterations of %s took: %.3f secs" % (iters, func, end -
start)
       print len(r), [:5]       # never hurts to get some validation that
the function works at all
>
> was used on the python list Friday for similar testing.
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>