Re: Passing function objects to timeit

2008-04-01 Thread Peter Otten
George Sakkis wrote: > I'm afraid that the taken approach is worse than your patch. For one > thing, it allows only zero-arg functions. Of course one can work > around it by passing "lambda: f(...)" but that's adding extra overhead > which can be measurable for small fast functions. Even if passin

Re: Passing function objects to timeit

2008-03-31 Thread George Sakkis
On Mar 31, 6:15 am, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > On Mar 30, 9:03 am, Peter Otten <[EMAIL PROTECTED]> wrote: > >> Steven D'Aprano wrote: > >> > On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: > > >> >> Second try: > >> > ... > >> >> Horrible, I know.

Re: Passing function objects to timeit

2008-03-31 Thread Peter Otten
George Sakkis wrote: > On Mar 30, 9:03 am, Peter Otten <[EMAIL PROTECTED]> wrote: >> Steven D'Aprano wrote: >> > On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: >> >> >> Second try: >> > ... >> >> Horrible, I know. Those wrapper1,wrapper2,wrapper3... keep growing >> >> with each call.

Re: Passing function objects to timeit

2008-03-30 Thread Steven D'Aprano
On Sun, 30 Mar 2008 15:03:21 +0200, Peter Otten wrote: > Maybe the following enhancement of timeit would be worthwhile? [snip] Passing a namespace argument would be excellent. > By the way, haven't we been there before, two years ago? > > http://mail.python.org/pipermail/python-list/2006-Februa

Re: Passing function objects to timeit

2008-03-30 Thread George Sakkis
On Mar 30, 9:03 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: > > >> Second try: > > ... > >> Horrible, I know. Those wrapper1,wrapper2,wrapper3... keep growing with > >> each call. But it's the only way I could

Re: Passing function objects to timeit

2008-03-30 Thread Peter Otten
Steven D'Aprano wrote: > On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: > >> Second try: > ... >> Horrible, I know. Those wrapper1,wrapper2,wrapper3... keep growing with >> each call. But it's the only way I could find, at least without changing >> the code template used by timeit.

Re: Passing function objects to timeit

2008-03-30 Thread Steven D'Aprano
On Sun, 30 Mar 2008 10:55:25 +, Steven D'Aprano wrote: > Perhaps it's time for me to take a different approach. Since I can't > call timeit, and I can't inherit from it (same problem with state being > shared between instances), perhaps I should write my own timer. > > > import timeit > impo

Re: Passing function objects to timeit

2008-03-30 Thread Steven D'Aprano
On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: > Second try: ... > Horrible, I know. Those wrapper1,wrapper2,wrapper3... keep growing with > each call. But it's the only way I could find, at least without changing > the code template used by timeit. Eeek. Talk about namespace pollut

Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
On Sun, 30 Mar 2008 00:27:45 -0300, Gabriel Genellina wrote: > En Sat, 29 Mar 2008 23:23:07 -0300, Steven D'Aprano > <[EMAIL PROTECTED]> escribió: > >> The general problem is that I wish to time an arbitrary function with >> arbitrary arguments. The function and arguments are provided to me as >>

Re: Passing function objects to timeit

2008-03-29 Thread Gabriel Genellina
En Sun, 30 Mar 2008 00:20:34 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > On Sat, 29 Mar 2008 21:12:33 -0300, Gabriel Genellina wrote: > >> def main(): >>global func >>func = factory() >>return timeit.Timer('func()', 'from __main__ import func').timeit() > > Alas, this does

Re: Passing function objects to timeit

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 23:23:07 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > The general problem is that I wish to time an arbitrary function with > arbitrary arguments. The function and arguments are provided to me as > Python objects, but timeit requires strings. Converting the objects

Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 21:12:33 -0300, Gabriel Genellina wrote: > Or maybe: > > def main(): >global func >func = factory() >return timeit.Timer('func()', 'from __main__ import func').timeit() Alas, this does not work, because all the Timer instances share the same state. import time

Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 21:12:33 -0300, Gabriel Genellina wrote: > En Sat, 29 Mar 2008 07:33:40 -0300, Steven D'Aprano > <[EMAIL PROTECTED]> escribió: > >> The timeit.Timer class times "code snippets" -- you pass it strings >> rather than function objects. That's good for what it's worth, but >> some

Re: Passing function objects to timeit

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 07:33:40 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > The timeit.Timer class times "code snippets" -- you pass it strings > rather than function objects. That's good for what it's worth, but > sometimes the code you want to time is too big to easily pass as a > stri

Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
The timeit.Timer class times "code snippets" -- you pass it strings rather than function objects. That's good for what it's worth, but sometimes the code you want to time is too big to easily pass as a string, or maybe you only have access to a function object without the source, or for whateve