Re: pointless musings on performance

2009-11-26 Thread Paul Boddie
On 25 Nov, 13:11, Antoine Pitrou solip...@pitrou.net wrote: When you say executing each kind of bytecode instruction, are you talking about the overhead of bytecode dispatch and operand gathering, or the total cost including doing the useful work? Strip away any overhead (dispatch, operand

Re: pointless musings on performance

2009-11-25 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 22:08:19 +, Benjamin Peterson a écrit : Would it be worth in-lining the remaining part of PyObject_IsTrue in ceval? Inlining by hand is prone to error and maintainability problems. Which is why we like to do it :-)) --

Re: pointless musings on performance

2009-11-25 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 16:09:10 -0800, Paul Boddie a écrit : I'm referring to what you're talking about at the end. The enhancements in Python 3 presumably came about after discussion of threaded interpreters, confirming that the evaluation loop in Python 2 was not exactly optimal. An optimal

pointless musings on performance

2009-11-24 Thread mk
#!/usr/local/bin/python import timeit def pythonic(): nonevar = None zerovar = 0 for x in range(100): if nonevar: pass if zerovar: pass def unpythonic(): nonevar = None zerovar = 0 for x in range(100): if nonevar

Re: pointless musings on performance

2009-11-24 Thread MRAB
mk wrote: #!/usr/local/bin/python import timeit def pythonic(): nonevar = None zerovar = 0 for x in range(100): if nonevar: pass if zerovar: pass def unpythonic(): nonevar = None zerovar = 0 for x in range(100):

Re: pointless musings on performance

2009-11-24 Thread Rob Williscroft
mk wrote in news:mailman.915.1259064240.2873.python-l...@python.org in comp.lang.python: def pythonic(): def unpythonic(): Decidedly counterintuitive: are there special optimizations for if nonevar: type of statements in cpython implementation? from dis import dis dis(

Re: pointless musings on performance

2009-11-24 Thread Chris Rebert
On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft r...@freenet.co.uk wrote: mk wrote in news:mailman.915.1259064240.2873.python-l...@python.org in comp.lang.python: def pythonic(): def unpythonic(): Decidedly counterintuitive: are there special optimizations for if nonevar: type of

Re: pointless musings on performance

2009-11-24 Thread mk
MRAB wrote: In what way is it counterintuitive? In 'pythonic' the conditions are simpler, less work is being done, therefore it's faster. But the pythonic condition is more general: nonevar or zerovar can be '', 0, or None. So I thought it was more work for interpreter to compare those,

Re: pointless musings on performance

2009-11-24 Thread Rob Williscroft
mk wrote in news:mailman.923.1259070092.2873.python-l...@python.org in comp.lang.python: MRAB wrote: In what way is it counterintuitive? In 'pythonic' the conditions are simpler, less work is being done, therefore it's faster. But the pythonic condition is more general: nonevar or zerovar

Re: pointless musings on performance

2009-11-24 Thread Antoine Pitrou
Hello, Le Tue, 24 Nov 2009 14:41:19 +0100, mk a écrit : As Rob pointed out (thanks): 11 31 LOAD_FAST0 (nonevar) 34 JUMP_IF_FALSE4 (to 41) I'm no good at py compiler or implementation internals and so I have no idea what bytecode

Re: pointless musings on performance

2009-11-24 Thread Neil Cerutti
On 2009-11-24, Antoine Pitrou solip...@pitrou.net wrote: It tries to evaluate the op of the stack (here nonevar) in a boolean context (which theoretically involves calling __nonzero__ on the type) ...or __bool__ in Py3K. -- Neil Cerutti --

Re: pointless musings on performance

2009-11-24 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 15:11:29 +, Antoine Pitrou a écrit : Hello, Le Tue, 24 Nov 2009 14:41:19 +0100, mk a écrit : As Rob pointed out (thanks): 11 31 LOAD_FAST0 (nonevar) 34 JUMP_IF_FALSE4 (to 41) I'm no good at py compiler or

Re: pointless musings on performance

2009-11-24 Thread Paul Boddie
On 24 Nov, 16:11, Antoine Pitrou solip...@pitrou.net wrote: [JUMP_IF_FALSE] It tries to evaluate the op of the stack (here nonevar) in a boolean context (which theoretically involves calling __nonzero__ on the type) and then jumps if the result is False (rather than True). [...] As

Re: pointless musings on performance

2009-11-24 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a écrit : As you point out, a lot of this RISC vs. CISC analysis (and inferences drawn from Python bytecode analysis) is somewhat academic: the cost of the JUMP_IF_FALSE instruction is likely to be minimal in the context of all the activity

Re: pointless musings on performance

2009-11-24 Thread Tim Wintle
On Tue, 2009-11-24 at 18:25 +, Antoine Pitrou wrote: Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a écrit : As you point out, a lot of this RISC vs. CISC analysis (and inferences drawn from Python bytecode analysis) is somewhat academic: the cost of the JUMP_IF_FALSE instruction

Re: pointless musings on performance

2009-11-24 Thread Benjamin Peterson
Tim Wintle tim.wintle at teamrubber.com writes: Out of interest - has anyone else spotted that the call to PyObject_IsTrue in the XXX_JUMP_IF_ blocks performs two unnecessary pointer comparisons? I doubt two pointer comparisons will make much of a difference. Would it be worth in-lining

Re: pointless musings on performance

2009-11-24 Thread Terry Reedy
Chris Rebert wrote: On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft r...@freenet.co.uk wrote: mk wrote in news:mailman.915.1259064240.2873.python-l...@python.org in comp.lang.python: def pythonic(): def unpythonic(): Decidedly counterintuitive: are there special optimizations for if

Re: pointless musings on performance

2009-11-24 Thread Paul Boddie
On 24 Nov, 19:25, Antoine Pitrou solip...@pitrou.net wrote: Sorry, I have trouble parsing your sentence. Do you mean bytecode interpretation overhead is minimal compared to the cost of actual useful work, or the contrary? (IMO both are wrong by the way) I'm referring to what you're talking