Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut ===
from timeit import Timer
def func
Steven D'Aprano schrieb am 10.05.2015 um 11:58:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut ===
from timeit import Timer
def func():
a = 2
On 11/05/2015 04:58, Steven D'Aprano wrote:
On Mon, 11 May 2015 07:08 am, BartC wrote:
On 10/05/2015 10:58, Steven D'Aprano wrote:
def func():
a = 2
b = 3
c = 4
return (a+b)*(a-b)/(a*c + b*c)
print (min(t1.repeat(repeat=10)))
print (min(t2.repeat(repeat=10)))
On Mon, May 11, 2015 at 10:01 AM, BartC b...@freeuk.com wrote:
(1) It has an extra argument ('code'), in addition to any normal arguments
of func (0 in this case)
Which might well push execution down the unoptimized code path. Also,
ISTR that Steven's original timeit runs tacked on a standalone
On Mon, May 11, 2015 at 4:50 AM, BartC b...@freeuk.com wrote:
You just seem surprised that using eval() to do this is slower than a
direct call.
Well, it is surprising. Most uses of eval() are to evaluate Python
expressions in string form. That I expect to be quite slow, given the
On 11/05/2015 15:12, Skip Montanaro wrote:
On Mon, May 11, 2015 at 4:50 AM, BartC b...@freeuk.com
mailto:b...@freeuk.com wrote:
You just seem surprised that using eval() to do this is slower than
a direct call.
Well, it is surprising. Most uses of eval() are to evaluate Python
On 10/05/2015 10:58, Steven D'Aprano wrote:
from timeit import Timer
def func():
a = 2
b = 3
c = 4
return (a+b)*(a-b)/(a*c + b*c)
code = func.__code__
assert func() == eval(code)
t1 = Timer(eval; func(), setup=from __main__ import func)
t2 = Timer(eval(code), setup=from
On Mon, 11 May 2015 07:08 am, BartC wrote:
On 10/05/2015 10:58, Steven D'Aprano wrote:
from timeit import Timer
def func():
a = 2
b = 3
c = 4
return (a+b)*(a-b)/(a*c + b*c)
code = func.__code__
assert func() == eval(code)
t1 = Timer(eval; func(), setup=from
Steven D'Aprano wrote:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Directly eval'ing the code object is easily more than twice as expensive
than calling the function, but calling the function
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut ===
from timeit import Timer
def func():
a = 2
b = 3
c = 4
return (a+b)*(a-b)/(a*c + b*c
Am 10.05.15 um 11:58 schrieb Steven D'Aprano:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut ===
from timeit import Timer
def func():
a = 2
b
On 5/10/2015 5:58 AM, Steven D'Aprano wrote:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut ===
from timeit import Timer
def func():
a = 2
b = 3
On Sun, 10 May 2015 08:43 pm, Peter Otten wrote:
A significant part of the extra time is apparently spent on stack
inspection:
I don't know what you mean by stack inspection, or how you come to that
conclusion.
$ python3 -m timeit -s 'f = (lambda: 42); code = f.__code__; ns = {}'
'f()'
Steven D'Aprano wrote:
On Sun, 10 May 2015 08:43 pm, Peter Otten wrote:
A significant part of the extra time is apparently spent on stack
inspection:
I don't know what you mean by stack inspection, or how you come to that
conclusion.
$ python3 -m timeit -s 'f = (lambda: 42); code =
On Sun, 10 May 2015 08:34 pm, Christian Gollwitzer wrote:
Am 10.05.15 um 11:58 schrieb Steven D'Aprano:
Why is calling a function faster than bypassing the function object and
evaluating the code object itself? And not by a little, but by a lot?
Here I have a file, eval_test.py:
# === cut
On Sun, May 10, 2015 at 10:14 AM, Peter Otten __pete...@web.de wrote:
When there was an actual speed-up I also had a look at
PyEval_GetGlobals/Locals() which in turn call
PyEval_GetFrame()
and
PyEvalPyFrame_FastToLocalsWithError()
whatever these do. (The first function reminded me of
16 matches
Mail list logo