Python Performance Part 3: Python 3000 and Transforming Large Lists into Seperate Smaller Lists

Preface

This is a redux of Python Performance Part 1, where the fastest method was using the reduce builtin function in Python2.5. December 3rd, Python 3000 final was released so I have downloaded it and gone over some of these scripts again. In Python 3000 the reduce function is no longer a builtin, and has moved to the module functools. When doing some general comparisons between Python2.5 and Python 3000, the later seemed to always run slightly slower. This is due to the new IO system and unicode indentifiers, as I was told in #python channel by Crys_. It was also recommended that I also compare my tests with List Comprehension, of which is new to me.

List Comprehension

from oids import oids as a
c = 3
res = [a[x:x+c] for x in [c*x for x in range(int(round(len(a)/c)))]]

Python 3k Times

real  0m0.218s
user  0m0.180s
sys   0m0.016s

real  0m0.262s
user  0m0.204s
sys   0m0.032s

real  0m0.287s
user  0m0.244s
sys   0m0.008s

Python 2.5 Times

real  0m0.244s
user  0m0.220s
sys   0m0.016s

real  0m0.229s
user  0m0.208s
sys   0m0.020s

real  0m0.251s
user  0m0.236s
sys   0m0.020s

This makes it the fastest method, beating the previous fastest time of 0.34s. Even better, there is little difference between Python2.5 and Python3000 here.




Leave a Reply

Previous

Python Performance Part 2 Redux: Split & Reduce Large Strings for ‘A Href’ Hypertext

split_2.py def get_value(a): return a[1:a.find(">")-1] hrefs = map(get_value,open(“hypertext.html”,”r”).read().split(“<a href=”)) Timing Comparison: ~ 300% Performance Improvement Note: hypertext.html is 48MB. braydon@bgf:~/python_tests/extract$ time python split.py real 0m1.263s user 0m1.112s sys 0m0.156s braydon@bgf:~/python_tests/extract$ time python split_2.py real 0m0.392s user 0m0.268s sys 0m0.120s split.py…

Next

InDefero — Code Hosting and Project Management

While at SCaLE 9x this last weekend I went to a talk on “Behind the Scenes of Google Code Project Hosting”. I had previously just discovered InDefero, a project that started out as using a similar user interface but is…



News Calendar

December 2008
M T W T F S S
« Jun   Feb »
1234567
891011121314
15161718192021
22232425262728
293031