Getting values out of a CSV

Kelvie Wong kelvie at ieee.org
Fri Jul 13 17:15:48 EDT 2007


Hrm.  Repeating the test several more times, it seems that the value
fluctuates, sometimes one's faster than the other, and sometimes
they're the same.

Perhaps the minute difference between the two is statistically
insignificant?  Or perhaps the mechanism underlying both (i.e. the
implementation) is the same?

On 7/13/07, Daniel <no at no.no> wrote:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Kelvie



More information about the Python-list mailing list