Statement coverage tools revisited

Nick Coghlan ncoghlan at iinet.net.au
Fri Feb 11 08:42:17 EST 2005


Edvard Majakari wrote:
> ,----
> | The coverage dictionary is called "c" and the trace function
> | "t".  The reason for these short names is that Python looks up variables
> | by name at runtime and so execution time depends on the length of
> | variables!  In the bottleneck of this application it's appropriate to
> | abbreviate names to increase speed.
> `----
> 
> It was written when 2.1 was the most recent stable version. I wonder if it
> still applies for 2.2 and later? According to my hasty tests it doesn't
> seem to be so. I didn't have very large unit test files at hand, though.

It's no longer correct (if it ever was correct). Python internalises 'short' 
strings (including identifiers) so that comparison can generally be done by 
means of identity checks.

Py> long_and_really_complicated_var_name = 1
Py> "long_and_really_complicated_var_name" is "long_and_really_complicated_var_n
ame"
True
Py> "long_and_really_complicated_non_var_name" is "long_and_really_complicated_n
on_var_name"
True
Py> "long_and_really_complicated_non_var_name" * 20 is "long_and_really_complica
ted_non_var_name" * 20
False

Ah, the wonderful efficiencies of immutable types. . .

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list