Kaydet (Commit) 9a2310d1 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 65240-65242 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r65240 | antoine.pitrou | 2008-07-26 00:02:07 +0200 (sam., 26 juil. 2008) | 3 lines

  add a pybench test for complex function calls (part of #1819)
........
  r65241 | antoine.pitrou | 2008-07-26 00:13:52 +0200 (sam., 26 juil. 2008) | 4 lines

  Raymond's patch for #1819: speedup function calls with named parameters
  (35% faster according to pybench)
........
  r65242 | antoine.pitrou | 2008-07-26 00:22:08 +0200 (sam., 26 juil. 2008) | 3 lines

  add a NEWS entry
........
üst 83d6a87a
......@@ -9,6 +9,12 @@ What's new in Python 3.0b3?
*Release date: XX-XXX-2008*
Core and Builtins
-----------------
- Issue #1819: function calls with several named parameters are now on
average 35% faster (as measured by pybench).
Library
-------
......
......@@ -2650,6 +2650,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
}
}
for (i = 0; i < kwcount; i++) {
PyObject **co_varnames;
PyObject *keyword = kws[2*i];
PyObject *value = kws[2*i + 1];
int j;
......@@ -2659,16 +2660,25 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
co->co_name);
goto fail;
}
/* XXX slow -- speed up using dictionary? */
/* Speed hack: do raw pointer compares. As names are
normally interned this should almost always hit. */
co_varnames = PySequence_Fast_ITEMS(co->co_varnames);
for (j = 0;
j < co->co_argcount + co->co_kwonlyargcount;
j++) {
PyObject *nm = PyTuple_GET_ITEM(
co->co_varnames, j);
PyObject *nm = co_varnames[j];
if (nm == keyword)
goto kw_found;
}
/* Slow fallback, just in case */
for (j = 0;
j < co->co_argcount + co->co_kwonlyargcount;
j++) {
PyObject *nm = co_varnames[j];
int cmp = PyObject_RichCompareBool(
keyword, nm, Py_EQ);
if (cmp > 0)
break;
goto kw_found;
else if (cmp < 0)
goto fail;
}
......@@ -2685,8 +2695,9 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
goto fail;
}
PyDict_SetItem(kwdict, keyword, value);
continue;
}
else {
kw_found:
if (GETLOCAL(j) != NULL) {
PyErr_Format(PyExc_TypeError,
"%U() got multiple "
......@@ -2699,7 +2710,6 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_INCREF(value);
SETLOCAL(j, value);
}
}
if (co->co_kwonlyargcount > 0) {
for (i = co->co_argcount;
i < co->co_argcount + co->co_kwonlyargcount;
......
......@@ -109,6 +109,64 @@ class PythonFunctionCalls(Test):
###
class ComplexPythonFunctionCalls(Test):
version = 2.0
operations = 4*5
rounds = 100000
def test(self):
# define functions
def f(a,b,c,d=1,e=2,f=3):
return f
args = 1,2
kwargs = dict(c=3,d=4,e=5)
# do calls
for i in range(self.rounds):
f(a=i,b=i,c=i)
f(f=i,e=i,d=i,c=2,b=i,a=3)
f(1,b=i,**kwargs)
f(*args,**kwargs)
f(a=i,b=i,c=i)
f(f=i,e=i,d=i,c=2,b=i,a=3)
f(1,b=i,**kwargs)
f(*args,**kwargs)
f(a=i,b=i,c=i)
f(f=i,e=i,d=i,c=2,b=i,a=3)
f(1,b=i,**kwargs)
f(*args,**kwargs)
f(a=i,b=i,c=i)
f(f=i,e=i,d=i,c=2,b=i,a=3)
f(1,b=i,**kwargs)
f(*args,**kwargs)
f(a=i,b=i,c=i)
f(f=i,e=i,d=i,c=2,b=i,a=3)
f(1,b=i,**kwargs)
f(*args,**kwargs)
def calibrate(self):
# define functions
def f(a,b,c,d=1,e=2,f=3):
return f
args = 1,2
kwargs = dict(c=3,d=4,e=5)
# do calls
for i in range(self.rounds):
pass
###
class BuiltinFunctionCalls(Test):
version = 2.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment