Name
calibrate
Synopsis
p.calibrate(N)Loops N times, then returns a number that
is the profiling overhead per call on your machine.
N must be large if your machine is fast.
Call p
.calibrate(10000)
a few times and check that the various numbers it returns are very
close to each other, then pick the smallest one of them. If the
numbers exhibit substantial variation, try again with larger values
of N.
The calibration procedure can be time consuming. However, you need to
perform it only once, repeating it only when you make changes that
could alter your machine’s characteristics, such as
applying patches to your operating system, adding memory, or changing
Python version. Once you know your machine’s
overhead, you can tell profile about it each time
you import it, right before using profile.run. The
simplest way to do this is as follows:
import profile
profile.Profile.bias = ...the overhead you measured...
profile.run('main( )', 'somefile')Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access