python - timeit returning a negative value occasionally, possible bug in timeit -
I have worked on problems and decided to add time, so the time from timeit
main ()
global RESULT
for convenience) through the following snippet (code
T = timeit timetable (main, 'gc.enable ()', number = 1) print ("#user", problem, ".. RESULT:", RESULT))
OK Works but, while walking so fast, I thought I could do this.
t = timeit.timeit (main, 'gc.enable ()', number = 1) if (T & lt; 0.001): T2 = timeit.timeit (main, 'gc. Enable () ', number = 1000) and it sometimes works, even if I run it repeatedly, I give negative value for T2 for some time. For example, using Euler # 2, I get these results from running this 5 times in a row. # Euler2.py Result:. 4,613,732 3.17869758716347e-05 seconds Per-time -3.7966224778973e-05 seconds Repeats Phone # Euler2.py Result: 4,613,732 3.1558464885145785e-05 seconds time 2.4836235955056177e-05 per call # Euler2.py results repeating seconds: 4,613,732 3.131149340411519e-05 seconds replay -3.5684903805855466e-05 per call # Euler2.py results seconds: 4613732 repeats 3kl7745025645ll94e-05 seconds per call # Euler2.py results when 2.4558941864410162e-05 seconds: 4613732 3.158939868681022e-05 second call
Repeats 2.4268726425449536e-05 seconds per time
Now if I re-count 100,000 or more Change in a stronger me negative T2 value does not appear at all and the time per call constantly 2.4e-5 s around to call.
If I repeat 10,000 times, I see new behavior. T2 is consistently positive, but the price bounces around a lot. 10 runs I get
repeats time 2.4194581894745244e-05 call repeats repeats per second Call repeats per 2.4408832248987168e-05 seconds call time per 1.8200670315524775e-05 seconds per 2.4378118077314547e -05 seconds call repeats time 1.8361976570139902e-05 seconds repeats calls per repeats time 1.8055080028738498e-05 seconds repeats calls per time 1.8102133534236732e-05 seconds per call repeats time 2.4485323058654477e-05 seconds per call repeats time 3kll836308799l698e-05 seconds per call Time 1.80384640868541 3e -05 sec per call
Finally, set the repeat count to 1000 and the initial (repeat = 1) timetable has been removed. Result of the same time, some negative and too much bounce
I repeated this set of Python 2.7, similar results - everything else was version 3.4
For me, this time A bug looks like when the total time system is in the same order as between the timer, but I thought maybe I'm missing something.
ADDED
I should also add that I know about other timer functions including perf_counter ().
I am specifically asking about time () because I thought that using the Hi-Hers timer is easy, I can use it in newer and older versions of Python and if doing so Can be trusted but want to continue.
ADDED
Based on the answer given to me, I changed the BSE on my timing code pef_counter () and made sure that I sometimes get negative values too. Therefore, if you use on the old window box, the scales of time are not reliable. This is what I wanted to know. I think it was in the Python Stack that for a very short time, the value seemed right. It should be guessed that it was a combination of Windows and device drivers.
On Windows, code> time.clock as your time source, which will change In Windows API, the uses QueryPerformanceCounter
. Based on the version of Windows and machine capabilities, QueryPerformanceCounter
uses the processor's Time Stamp Counter (TSC) as a timer. The old multiprocessor machine was not able to keep the TSC in synchronization between the processors and it did not report Windows correctly, or was a bug trying to do this.
Microsoft has a detailed description of the problem on MSDN:
AMD has a problem for Windows XP system Fix released.
Comments
Post a Comment