Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54181 > unrolled thread

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

Started byTal Bar-Or <tbaror@gmail.com>
First post2013-09-14 19:59 -0700
Last post2013-09-15 11:31 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  How to get time (milisecond) of a python IO execution Tal Bar-Or <tbaror@gmail.com> - 2013-09-14 19:59 -0700
    Re: How to get time (milisecond) of a python IO execution Skip Montanaro <skip@pobox.com> - 2013-09-15 05:52 -0500
    Re: How to get time (milisecond) of a python IO execution Dave Angel <davea@davea.name> - 2013-09-15 11:31 +0000

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

FromTal Bar-Or <tbaror@gmail.com>
Date2013-09-14 19:59 -0700
SubjectHow to get time (milisecond) of a python IO execution
Message-ID<8baf5318-f82c-417d-9a1d-956bf9cb3856@googlegroups.com>
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))

[toc] | [next] | [standalone]


#54186

FromSkip Montanaro <skip@pobox.com>
Date2013-09-15 05:52 -0500
Message-ID<mailman.386.1379242355.5461.python-list@python.org>
In reply to#54181
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

[toc] | [prev] | [next] | [standalone]


#54187

FromDave Angel <davea@davea.name>
Date2013-09-15 11:31 +0000
Message-ID<mailman.0.1379244724.18130.python-list@python.org>
In reply to#54181
On 14/9/2013 22:59, Tal Bar-Or wrote:

> 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.


-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web