list.clear() missing?!?

Dan Christensen jdc at uwo.ca
Tue Apr 11 20:58:37 EDT 2006


Felipe Almeida Lessa <felipe.lessa at gmail.com> writes:

> I love benchmarks, so as I was testing the options, I saw something very
> strange:
>
> $ python2.4 -mtimeit 'x = range(100000); '
> 100 loops, best of 3: 6.7 msec per loop
> $ python2.4 -mtimeit 'x = range(100000); del x[:]'
> 100 loops, best of 3: 6.35 msec per loop
> $ python2.4 -mtimeit 'x = range(100000); x[:] = []'
> 100 loops, best of 3: 6.36 msec per loop
> $ python2.4 -mtimeit 'x = range(100000); del x'
> 100 loops, best of 3: 6.46 msec per loop
>
> Why the first benchmark is the slowest? I don't get it... could someone
> test this, too?

I get similar behaviour.  No idea why.

$ python2.4 -mtimeit 'x = range(100000); '
100 loops, best of 3: 6.99 msec per loop
$ python2.4 -mtimeit 'x = range(100000); del x[:]'
100 loops, best of 3: 6.49 msec per loop
$ python2.4 -mtimeit 'x = range(100000); x[:] = []'
100 loops, best of 3: 6.47 msec per loop
$ python2.4 -mtimeit 'x = range(100000); del x'
100 loops, best of 3: 6.6 msec per loop

Dan



More information about the Python-list mailing list