Timing short pieces of code is incredibly complex. How much processor time is your computer devoting to running
this code? Are there things running in the background? Are you sure? Every modern computer has background
processes running, some all the time, some intermittently. Cron jobs fire off at consistent intervals; background
services occasionally "wake up" to do useful things like check for new mail, connect to instant messaging servers,
check for application updates, scan for viruses, check whether a disk has been inserted into your CD drive in the last
100 nanoseconds, and so on. Before you start your timing tests, turn everything off and disconnect from the network.
Then turn off all the things you forgot to turn off the first time, then turn off the service that's incessantly checking
whether the network has come back yet, then ...
And then there's the matter of the variations introduced by the timing framework itself. Does the Python interpreter
cache method name lookups? Does it cache code block compilations? Regular expressions? Will your code have side
effects if run more than once? Don't forget that you're dealing with small fractions of a second, so small mistakes in
your timing framework will irreparably skew your results.
this code? Are there things running in the background? Are you sure? Every modern computer has background
processes running, some all the time, some intermittently. Cron jobs fire off at consistent intervals; background
services occasionally "wake up" to do useful things like check for new mail, connect to instant messaging servers,
check for application updates, scan for viruses, check whether a disk has been inserted into your CD drive in the last
100 nanoseconds, and so on. Before you start your timing tests, turn everything off and disconnect from the network.
Then turn off all the things you forgot to turn off the first time, then turn off the service that's incessantly checking
whether the network has come back yet, then ...
And then there's the matter of the variations introduced by the timing framework itself. Does the Python interpreter
cache method name lookups? Does it cache code block compilations? Regular expressions? Will your code have side
effects if run more than once? Don't forget that you're dealing with small fractions of a second, so small mistakes in
your timing framework will irreparably skew your results.
Comments
Post a Comment
https://gengwg.blogspot.com/