list addition methods compared.

Ishwor ishwor.gurung at gmail.com
Tue Dec 28 19:11:35 EST 2004


On Mon, 27 Dec 2004 18:49:14 +0100, François Granger
<fgranger at fgranger.com> wrote:
> Le 27/12/04 1:03, « Ishwor » <ishwor.gurung at gmail.com> a écrit :
> 
> > so indeed method 2 (l2.extend() ) is the fastest ?? In 2/3 times,
> > method 3 (l3 += [x] seems faster than method 1/2 in my P2.4GHZ machine
> > with 512mb??? :-(
> > Could u run the code in your machine and perhaps and let me know what
> > the average speed is??
> 
> On a iBook G4 à 1.2 Ghz loaded with tons of other softwares running.
> 
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@@@@@
> Method 1 done in (average finish time(out of 3)) - 5.6365475655
> Method 2 done in (average finish time(out of 3)) - 0.0562076569
> Method 3 done in (average finish time(out of 3)) - 0.0455052853
> @@@@@@@
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@@@@@
> Method 1 done in (average finish time(out of 3)) - 6.1534483433
> Method 2 done in (average finish time(out of 3)) - 0.0637686253
> Method 3 done in (average finish time(out of 3)) - 0.0500767231
> @@@@@@@
> fgranger:/develop/python scripts fgranger$ python listspeed.py
> @@@@@@@
> Method 1 done in (average finish time(out of 3)) - 5.5850391388
> Method 2 done in (average finish time(out of 3)) - 0.0594174862
> Method 3 done in (average finish time(out of 3)) - 0.0549054146
> @@@@@@@
> 
Thank you. ;-) method 3 ( l += [x] which maps to l.extend([x]) )
indeed seems fastest. well anyway i'll be using timeit module from now
onwards as Steve pointed out. Thank you.

[snip]
-- 
"On a cold day please heat your laptop using
>>>while 1: pass " ;-)
cheers,
Ishwor Gurung



More information about the Python-list mailing list