Fuller Web Development

  BLOG | CONTACT | CLIENTS

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.