[Metakit] Performance comparison Q

Magnus Lie Hetland magnus at hetland.org
Mon May 9 22:26:15 CEST 2005


Brian Kelley <fustigator at gmail.com>:
>
> python:
> ======
> import operator
> data = range(50000) # test data
> 
> result = sum(data)

I just did a simple experiment (using the timeit module) comparing
the performance of sum(range(50000)) and sum(xrange(50000)), and the
latter gave a speedup factor of about 2.2 on my computer... Also,
allocating a list of size 50000 seems a bit wasteful just for
computing this sum :)

-- 
Magnus Lie Hetland                    Fall seven times, stand up eight
http://hetland.org                                  [Japanese proverb]


More information about the Metakit mailing list