Statement coverage tools revisited

N

Nick Coghlan

Edvard said:
,----
| 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top