4 ms·
That's not really it. This, at least in my understanding, is a fully generic optimization, of operations on constant strings.
by TylerE 15y ago
That's not really it. This, at least in my understanding, is a fully generic optimization, of operations on constant strings.
- eridius 15y agoFrom the article: > In the case of PyPy, we specialize the assembler if we detect the left hand string of the modulo operator to be constant. So it's very much a targeted optimization at the modulo operator (which is Python's equivalent of sprintf).
- kingkilr 15y agoI wouldn't say it's particularly targeted, let me show you the code that makes this happen: https://bitbucket.org/pypy/pypy/src/unroll-if-alt/pypy/objspace/std/formatting.py#cl-288 https://bitbucket.org/pypy/pypy/src/unroll-if-alt/pypy/objsp...
- pja 15y agoYeah, the point is that by expressing the algorithm in Python, the JIT gets to go hog wild optimising tight loops like this one. Which is great: why do all that work writing some kind of custom sprintf generating function when you can just let the JIT do it for you on the fly?
- greyfade 15y agoIn that case, wouldn't it be more fair to compare it to a C++ re-implementation of sprintf using the new `constexpr` keyword?