[New-bugs-announce] [issue14453] profile.Profile.calibrate can produce incorrect numbers in some circumstances

Adam Tomjack report at bugs.python.org
Fri Mar 30 18:45:26 CEST 2012


New submission from Adam Tomjack <adam.tomjack at zuerchertech.com>:

profile.Profile.calibrate can only produces a bias for the default timer.  If you've specified a different timer, it will not be used when calibrating.

Additionally, setting profile.Profile.bias will affect the computed bias.  It will produce a bias that must be added to profile.Profile.bias and cannot be used independently, which is surprising.

The fix is to change
    p = Profile()
to 
    p = Profile(timer=self.timer, bias=0)
in _calibrate_inner().

The attached patch makes that change and additionally removes some code that temporarily resets self.bias in calibrate(), as it had no effect.  Perhaps Profile.bias was meant instead.  At any rate, _calibrate_inner() no longer needs to exist, but is left for backwards compatibility.

This will demonstrate the problem with calibrating after setting profile.Profile.bias:

import profile
profile.Profile.bias = profile.Profile().calibrate(100000); 
print '%+.9f' % profile.Profile.bias
profile.Profile.bias = profile.Profile().calibrate(100000); 
print '%+.9f' % profile.Profile.bias

----------
components: Library (Lib)
files: profile-calibrate.patch
keywords: patch
messages: 157145
nosy: adamtj
priority: normal
severity: normal
status: open
title: profile.Profile.calibrate can produce incorrect numbers in some circumstances
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file25073/profile-calibrate.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14453>
_______________________________________


More information about the New-bugs-announce mailing list