Unexpected timing results with file I/O

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Feb 4 16:58:46 EST 2008


On Mon, 04 Feb 2008 17:08:02 +0000, Marc 'BlackJack' Rintsch wrote:

>> Surprisingly, Method 2 is a smidgen faster, by about half a second over
>> 500,000 open-write-close cycles. It's not much faster, but it's
>> consistent, over many tests, changing many of the parameters (e.g. the
>> number of files, the number of runs per timeit test, etc.).
>> 
>> I'm using Linux and Python 2.5.
>> 
>> So, what's going on? Can anyone explain why the code which does more
>> work takes less time?
> 
> Can't confirm this (Linux, Python 2.5):
> 
> Method 1: 15.380897998809814
> Method 2: 18.085366010665894

Hmmm... does your system use software RAID? Mine does. I wonder if that's 
a relevant factor?

> I guess it's really all about the disk IO as my system monitor applet
> shows that almost all of the time is spend in the kernel and very little
> in user space.

I wouldn't be surprised if it was something to do with the OS caching 
writes to disk. And saying that is really just me doing a lot of hand-
waving and saying "it's magic of what we know naught".



-- 
Steven



More information about the Python-list mailing list