[issue1819] Speed hack for function calls with named parameters

Antoine Pitrou report at bugs.python.org
Mon Jan 14 01:48:21 CET 2008


New submission from Antoine Pitrou:

This is a patch for SVN trunk which substantially speeds up function
calls with named parameters. It does so by taking into account that
parameter names should be interned, so before doing full compares we do
a first quick loop to compare pointers.

On a microbenchmark the speedup is quite distinctive:

# With patch
$ ./python -m timeit -s "def f(a,b,c,d,e): pass" "f(1,2,3,4,e=5)"
1000000 loops, best of 3: 0.515 usec per loop
$ ./python -m timeit -s "def f(a,b,c,d,e): pass" "f(a=1,b=2,c=3,d=4,e=5)"
1000000 loops, best of 3: 0.652 usec per loop

# Without patch
$ ./python-orig -m timeit -s "def f(a,b,c,d,e): pass" "f(1,2,3,4,e=5)"
1000000 loops, best of 3: 0.664 usec per loop
$ ./python-orig -m timeit -s "def f(a,b,c,d,e): pass"
"f(a=1,b=2,c=3,d=4,e=5)"
1000000 loops, best of 3: 1.07 usec per loop

----------
components: Interpreter Core
files: namedparam.patch
messages: 59878
nosy: pitrou
severity: normal
status: open
title: Speed hack for function calls with named parameters
versions: Python 2.6
Added file: http://bugs.python.org/file9156/namedparam.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1819>
__________________________________


More information about the Python-bugs-list mailing list