Getting values out of a CSV

Daniel no at no.no
Fri Jul 13 12:13:24 EDT 2007


On Fri, 13 Jul 2007 16:18:38 +0300, Marc 'BlackJack' Rintsch  
<bj_666 at gmx.net> wrote:
>> $ python -m timeit -c 'import csv; data =  
>> list(csv.reader(open("some.csv",
>> "rb")))'
>> 10000 loops, best of 3: 44 usec per loop
>> $ python -m timeit -c 'import csv; data = [row for row in
>> csv.reader(open("some.csv", "rb"))]'
>> 10000 loops, best of 3: 37 usec per loop
>>
>> I don't know why there seems to be a differece, but I know that list  
>> comps
>> are python are very heavily optimised.
>
> Does the machine use power saving features like SpeedStep or
> something similar, i.e. runs the processor always with 100% speed or is  
> it
> dynamically stepped if there's load on the processor?  Do both tests read
> the data always from cache or has the very first loop had to fetch the  
> CSV
> file from disk?
>
> $ python -m timeit -n 1000 -c 'import csv; data = [row for row in
> csv.reader(open("test.csv", "rb"))]' 1000 loops, best of 3: 1.27 msec per
> loop
>
> $ python -m timeit -n 1000 -c 'import csv; data =
> list(csv.reader(open("test.csv", "rb")))' 1000 loops, best of 3: 1.25  
> msec
> per loop

No SpeedStep - tried a few repeats just in case files were cached,  
consistent 35usec for comp 40usec for list

Python 2.5.1 on Linux 1.2ghz

Even replacing the csv lookup with a straight variable declaration:  
[range(10)*3], same results

Weird.

Python



More information about the Python-list mailing list