I want to use python to test the time it takes for various windows applications (one being Acrobat Reader X) to load a file.
I can test the load time in opening and closing of files within Python code.
I know how to start a subprocess using Python and open a windows application that way, but that is not useful in this context because python calls the subprocess and continues through the script so the timer always reads 0.
Is there another method I can use to open a windows application, test it’s state (has the file loaded) and time that whole process?
There are different timing functions, with different semantics.
time.clock()return the time elapsed in the current process, whiletime.time()return the number of seconds since the epoch. This means that if you want to time an other process you should usetime.time()and nottime.clock().Example:
Probably there exist better solutions(*), and take into account PEP418 for python3.3.
Also I’d like to point out that it’s better to use the
profile/cProfileor thehotshotmodules to profile code. They give you plenty of more informations about timings.(*)
time.time()is affected if the administrator of the system changes the time of the computer, so it’s not guaranteed thattime.time() - time.time()will return a value greater or equal to zero, and also, even if it is positive, you cannot be sure if the timing is correct.Even though in normal situations, where the administrator wont change the time while you are profiling, this wont happen.