How to get time (milisecond) of a python IO execution

T

Tal Bar-Or

Hi All

i am trying to test measure some IO execution in milliseconds , but bit confuse about best method achive that under windows 7
i am using following code but not sure if its best or correct way since i have two different results, which one should i take as results
and which is best way
please advice
Thanks

code exec results
100000000 loops, best of 3: 0.00925 usec per loop
3.827947176762156


run code
import timeit ,time
import datetime
import os


def main():


os.path.getsize("c:/video-2011-09-09-09-32-29.mp4")


if __name__ == '__main__':

t = timeit.Timer('main()')

print (t.timeit(1))
 
S

Skip Montanaro

I'm not familiar with how Windows works, but I wouldn't be surprised
if it caches directory information. (Unix systems certainly would.)
You probably aren't really doing much actual I/O to get the size of a
file after the first run. Also, you probably want to subtract the time
it takes to execute a no-op function:

def noop(): pass

to eliminate the overhead of calling your main function.

Skip
 
D

Dave Angel

Hi All

i am trying to test measure some IO execution in milliseconds , but bit confuse about best method achive that under windows 7

Measuring any performance can be tricky, and I/O in particular. Windows
will cache the recently used file information, at a few levels. So if
you do the same thing repeatedly, you'll get an unnaturally low average
time.

if you really need to measure how long it takes to get a file size,
you would need to write your own, very controlled, test code. For
example, there is an APi call that tells Windows to flush its disk
caching logic. However, it doesn't necessarily flush the buffers that
the drive itself keeps. Worse, in order to run your program, you have
to do some disk I/O, and if that happens to use some of the same sectors
as the thing you're timing, you're biasing the results.

If you have multiple partitions, you could arrange that the file in
question is the only thing your system uses on that partition, to
minimize the likelihood that something else has primed the pump. But
realize also that once you're measuring the real thing, speed of
exeution will vary enormously depending on the speed of the drive, the
layout of the directories, and the fragmentation of the disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top