[Python-Dev] backticks delenda est
anthony at ekit-inc.com
Mon Dec 1 01:15:46 EST 2003
>>> "Raymond Hettinger" wrote
> Advisory from a micro-performance hawk: Backticks are faster than
> >>> from timeit import Timer
> >>> min(Timer('`x`', 'x=1').repeat(3))
> >>> min(Timer('repr(x)', 'x=1').repeat(3))
Presumably because the backtick version doesn't have to look up
'repr', then call it.
>>> def f1(a):
>>> def f2(a):
>>> import dis
2 0 LOAD_GLOBAL 0 (repr)
3 LOAD_FAST 0 (a)
6 CALL_FUNCTION 1
10 LOAD_CONST 0 (None)
2 0 LOAD_FAST 0 (a)
5 LOAD_CONST 0 (None)
This is presumably something that a future optimiser could "fix",
once we have the no-shadowing-builtins rule enforced.
I don't think this is a serious enough problem to merit leaving the
backticks in the std lib. I find them annoying, and hard to read.
In general, the backticks are in debugging and error handling code,
so the performance penalty should be negligible.
More information about the Python-Dev