On Friday 17 October 2003 11:45 pm, Phillip J. Eby wrote: ... > At 10:40 PM 10/17/03 +0200, Alex Martelli wrote: > >Yes, def curry(func, arg): return new.instancemethod(func, arg, object) ... > >def curry(func, arg): > > def curried(*args): return func(arg, *args) > > return curried ... > It is a big win if the curried function will be used in a > performance-sensitive way. Instance method objects don't pay for setting > up an extra frame object, and for the single curried argument, the > interpreter even shortcuts some of the instancemethod overhead! So, if I You're right: the instancemethod version has impressively better performance (should the curried function be used in a bottleneck, of course) -- i.e., given a.py: import new def curry1(func, arg): return new.instancemethod(func, arg, object) def curry2(func, arg): def curried(*args): return func(args, *args) return curried def f(a, b, c): return a, b, c I've measured: [alex at lancelot ba]$ timeit.py -c -s' import a g = a.curry2(a.f, 23) ' 'g(45, 67)' 100000 loops, best of 3: 2 usec per loop [alex at lancelot ba]$ timeit.py -c -s' import a g = a.curry1(a.f, 23) ' 'g(45, 67)' 1000000 loops, best of 3: 1.09 usec per loop I sure didn't expect an almost 2:1 ratio, while you did predict it. Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4