>>> "Raymond Hettinger" wrote > Advisory from a micro-performance hawk: Backticks are faster than > repr() > > >>> from timeit import Timer > >>> min(Timer('`x`', 'x=1').repeat(3)) > 1.4857213496706265 > >>> min(Timer('repr(x)', 'x=1').repeat(3)) > 1.7748914665012876 Presumably because the backtick version doesn't have to look up 'repr', then call it. >>> def f1(a): ... repr(a) ... >>> >>> def f2(a): ... `a` ... >>> import dis >>> dis.dis(f1) 2 0 LOAD_GLOBAL 0 (repr) 3 LOAD_FAST 0 (a) 6 CALL_FUNCTION 1 9 POP_TOP 10 LOAD_CONST 0 (None) 13 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_FAST 0 (a) 3 UNARY_CONVERT 4 POP_TOP 5 LOAD_CONST 0 (None) 8 RETURN_VALUE 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. Anthony
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4