Re: list.clear() missing?!?



On Wed, 12 Apr 2006 00:33:29 -0700, Serge Orlov wrote:


Felipe Almeida Lessa wrote:
Em Qua, 2006-04-12 às 11:36 +1000, Steven D'Aprano escreveu:
On Tue, 11 Apr 2006 19:15:18 +0200, Martin v. Löwis wrote:

Felipe Almeida Lessa wrote:
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?

In the first benchmark, you need space for two lists: the old one and
the new one;

Er, what new list? I see only one list, x = range(100000), which is merely
created then nothing done to it. Have I missed something?

He's talking about the garbage collector.

To be exact the reason for two array is timeit.py. It doesn't place the
code to time into a separate namespace but injects it into a for loop,
so the actual code timed is:
for _i in _it:
x = range(100000)
and that makes two arrays with 100.000 items exist for a short time
starting from second iteration.

But that is precisely the same for the other timeit tests too.

for _i in _it:
x = range(100000)
del x[:]

etc.

The question remains -- why does it take longer to do X than it takes to
do X and then Y?


--
Steven.

.



Relevant Pages

  • Re: Compare the values of two sorted arrays of variable size.
    ... This algorithm does not check for every possible location in each array. ... > contains a double loop where each element of the inner loop is compared ... > Dim lngMaxAIdx ' Upper value of the A list index. ... one of the lists has finished. ...
    (microsoft.public.scripting.vbscript)
  • Re: Reference other array objects from within loop?
    ... simulate trading programs in CL. ... each and every object in the array. ... facing right now is because of the nature of the code within the loop. ... Be careful with circular lists; don't pass them to LENGTH, and make sure to set *print-circle* to t. ...
    (comp.lang.lisp)
  • Re: [opensuse] bash - why doesnt the tldp bash beginners guide for loop example work?
    ... I have run into a bash problem with a simple for loop I don't ... The echo statement showed that $i was receiving the ... I personally like to use array variables in BASH scripting. ... lists to operate on. ...
    (SuSE)
  • Re: Uninterned symbols at macroexpansion time.
    ... (loop for somevar in '(some list here) ... so if we give the macro a gensym in ... collect (BACKQUOTE (UNQUOTE X)))) ... simple type (meaning eg symbols, lists, etc) not ...
    (comp.lang.lisp)
  • Re: Learning Lisp in Linux?
    ... To adapt the language to the task at hand? ... unless (member key excluded-keys) ... (loop (cddr property-list) ... correct property lists as results. ...
    (comp.lang.lisp)