Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Thomas Passin via Python-list
hope this is ok. >    I want to measure Postgres queries N times, much like Python timeit >    (https://docs.python.org/3/library/timeit.html). I know about EXPLAIN >    ANALYZE and psql \timing, but there's quite a bit of variation in the >   

Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Peter J. Holzer via Python-list
resql than to Python, I hope this is > ok. > >    I want to measure Postgres queries N times, much like Python timeit > >    (https://docs.python.org/3/library/timeit.html). I know about > EXPLAIN > >    ANALYZE and psql \timing, but there's qui

Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Thomas Passin via Python-list
On 9/17/2023 11:48 AM, AVI GROSS via Python-list wrote: Timing things that are fairly simple is hard enough to do repeatedly, but when it involves access to slower media and especially to network connections to servers, the number of things that can change are enormous. There are all kinds of

RE: Postgresql equivalent of Python's timeit?

2023-09-17 Thread AVI GROSS via Python-list
Python's timeit? On Sep 15, 2023 19:45, "Peter J. Holzer via Python-list" wrote: On 2023-09-15 17:42:06 +0200, Albert-Jan Roskam via Python-list wrote: >This is more related to Postgresql than to Python, I hope this is ok. >I want to measu

Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Albert-Jan Roskam via Python-list
times, much like Python timeit >    (https://docs.python.org/3/library/timeit.html). I know about EXPLAIN >    ANALYZE and psql \timing, but there's quite a bit of variation in the >    times. Is there a timeit-like function in Postgresql? Why not simp

Re: Postgresql equivalent of Python's timeit?

2023-09-15 Thread Peter J. Holzer via Python-list
On 2023-09-15 17:42:06 +0200, Albert-Jan Roskam via Python-list wrote: >This is more related to Postgresql than to Python, I hope this is ok. >I want to measure Postgres queries N times, much like Python timeit >(https://docs.python.org/3/library/timeit.html). I know abou

Postgresql equivalent of Python's timeit?

2023-09-15 Thread Albert-Jan Roskam via Python-list
Hi, This is more related to Postgresql than to Python, I hope this is ok. I want to measure Postgres queries N times, much like Python timeit (https://docs.python.org/3/library/timeit.html). I know about EXPLAIN ANALYZE and psql \timing, but there's quite a bit of variation i

Re: Problem with timeit

2017-12-19 Thread Steve D'Aprano
On Tue, 19 Dec 2017 02:27 am, ast wrote: > I discovered that log functions from math module > works with integers, whatever their size, there is > no conversion to float. > >> import math >> x = 123456**123456 >> math.log10(x) > 628577.7303641582 (instantaneous) > > so 628578 digits Nice! I

Re: Problem with timeit

2017-12-18 Thread ast
"Steve D'Aprano" a écrit dans le message de news:5a33d0fc$0$2087$b1db1813$d948b...@news.astraweb.com... On Sat, 16 Dec 2017 12:25 am, ast wrote: "Thomas Jollans" a écrit dans le message de news:mailman.74.1513341235.14074.python-l...@python.org... On 2017-12-15 11:36, ast wrote: p

Re: Problem with timeit

2017-12-15 Thread Bob van der Poel
**123456; print(time()-t) > > > > 0.0 > > Same here. > > > There is still something wrong > > As far as I can see, it's in your manual measurement. All of the code > you've provided gives the same results on my PC as on yours, but your > manual m

Re: Problem with timeit

2017-12-15 Thread ast
"ast" a écrit dans le message de news:5a33a5aa$0$10195$426a7...@news.free.fr... Ty Peter and Steve, I would never have found that explanation myself -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem with timeit

2017-12-15 Thread Paul Moore
3456; print(time()-t) > > 0.0 Same here. > There is still something wrong As far as I can see, it's in your manual measurement. All of the code you've provided gives the same results on my PC as on yours, but your manual measurements differ drastically from mine (and my man

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
on my >> system, it takes some 10 ns. The uncertainty of the timeit result is at >> least a few hundred nanoseconds. > > There are more than 10 multiplications to perform on a > soaring size integer. I have some doubts "x=123456**123456 " > only takes 10 ns

Re: Problem with timeit

2017-12-15 Thread ast
"Thomas Jollans" a écrit dans le message de news:mailman.74.1513341235.14074.python-l...@python.org... On 2017-12-15 11:36, ast wrote: No, this is right. The calculation takes practically no time; on my system, it takes some 10 ns. The uncertainty of the timeit result is at l

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 10:47 pm, Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python versio

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 09:36 pm, ast wrote: [...] > It's OK, with 10 more loops I get 10 more execution time. > > But with exponentiation, it's a mess > >>>> Timer("x=123456**123456").timeit(1) > 6.076191311876755e-06 >>>> Timer("x=12

Re: Problem with timeit

2017-12-15 Thread Peter Otten
Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python version 3.6.3 >> >> from timeit impo

Re: Problem with timeit

2017-12-15 Thread Thomas Jollans
On 2017-12-15 11:36, ast wrote: > Hi > > Time measurment with module timeit seems to work with some statements > but not with some other statements on my computer. > > Python version 3.6.3 > > from timeit import Timer > >>>> Timer("'-&

Problem with timeit

2017-12-15 Thread ast
Hi Time measurment with module timeit seems to work with some statements but not with some other statements on my computer. Python version 3.6.3 from timeit import Timer Timer("'-'.join([str(i) for i in range(10)])").timeit(1) 0.179271876732912 Timer("'

Re: Namespace for timeit

2016-10-14 Thread Skip Montanaro
> timeit('sorter( array, size )', number=1) I'm not a timeit whiz, but I'm kind of surprised there isn't a call form where it goes something like timeit(callable, *args, ...) There is a globals keyword argument though. I think you could probably call it w

Namespace for timeit

2016-10-14 Thread ROGER GRAYDON CHRISTMAN
Trying to use timeit within a function: def test(name, sorter, size): """Tests and times the sorting algorithm on given array size""" print(name,end='\t') array = [0]*size for i in range(size): array[i] = randrange(20)

Re: python : timeit - Tool for measuring execution time

2015-04-23 Thread anubhav1691
On Wednesday, April 22, 2015 at 10:20:58 PM UTC+5:30, Ganesh Pal wrote: > Thank you ,  this answers my question  : ) Hi, Thanks for asking this question, it introduced me to the timeit module. Just a friendly, next time refrain yourself from top posting. Cheers! -- https://mail.python.

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Ganesh Pal
; I have a hunch you're mistakenly thinking that Python is only running > through ten iterations of your for i in range(100) loop. This is > not the case. The entire thing is running (all 100 iterations of > your loop), but is run ten times, as that is the default for timeit > un

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Ian Kelly
loop), but is run ten times, as that is the default for timeit > unless you specify that you want to run it more times. Hope this helps. Actually, it's smarter than that. When running timeit from the command line, the default is to scale the number of loops according to the time taken.

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Michael Torrie
This is not the case. The entire thing is running (all 100 iterations of your loop), but is run ten times, as that is the default for timeit unless you specify that you want to run it more times. Hope this helps. Basically timeit is doing something like this: def mycode(): for i in ra

Re: python : timeit - Tool for measuring execution time

2015-04-21 Thread Ben Finney
best of 3: 51.1 msec per loop > > Iam not able to understand what why only 10 loops were run ? What behaviour did you expect? You didn't ask for any particular number of iterations, so you've allowed the tool to choose for you https://docs.python.org/3/library/timeit.html#cmdopt

python : timeit - Tool for measuring execution time

2015-04-21 Thread Ganesh Pal
Hi Team, Iam running the below command on Linux machine have Python 2.7 installed , I was trying to figure out the speed difference between xrange and range functions. range : python -m timeit 'for i in range(100):' ' pass' 10 loops, best of 3: 90.5 msec per loop $ p

Re: Strange result with timeit execution time measurment

2014-11-15 Thread Ian Kelly
.25)**2 + 1 if x < 0.5 else 16*(x-0.75)**2 - 1 > ------ > > then i used module timeit to compare its execution time with math.sin() > I put the sinusLite() function in a module named test. > > then: > >>>> import timeit >>>> t1

Re: Strange result with timeit execution time measurment

2014-11-15 Thread Peter Pearson
+ 1 if x < 0.5 else 16*(x-0.75)**2 - 1 > ------ > > then i used module timeit to compare its execution time with math.sin() > I put the sinusLite() function in a module named test. > > then: > >>>> import timeit >>>> t1 = timeit.Ti

Re:Strange result with timeit execution time measurment

2014-11-15 Thread Dave Angel
)**2 + 1 if x < 0.5 else 16*(x-0.75)**2 - 1 > ------ > > then i used module timeit to compare its execution time with math.sin() > I put the sinusLite() function in a module named test. > > then: > >>>> import timeit >>>> t1 = t

Re: Strange result with timeit execution time measurment

2014-11-15 Thread Peter Otten
f x < 0.5 else 16*(x-0.75)**2 - 1 > -- > > then i used module timeit to compare its execution time with math.sin() > I put the sinusLite() function in a module named test. > > then: > >>>> import timeit >>>> t1 = timeit.Timer("y=test.s

Strange result with timeit execution time measurment

2014-11-15 Thread ast
Hi I needed a function f(x) which looks like sinus(2pi.x) but faster. I wrote this one: -- from math import floor def sinusLite(x): x = x - floor(x) return -16*(x-0.25)**2 + 1 if x < 0.5 else 16*(x-0.75)**2 - 1 -- then i used module tim

Re: http://bugs.python.org/issue19495 timeit enhancement

2014-06-13 Thread Mark Lawrence
On 13/06/2014 01:44, Steven D'Aprano wrote: On Fri, 13 Jun 2014 00:35:43 +0100, Mark Lawrence wrote: The request is for a class within timeit that allows you to test code inside a with block. It strikes me as being useful but there's only one response on the issue, albeit a positiv

Re: http://bugs.python.org/issue19495 timeit enhancement

2014-06-12 Thread Cameron Simpson
On 13Jun2014 00:44, Steven D'Aprano wrote: On Fri, 13 Jun 2014 00:35:43 +0100, Mark Lawrence wrote: The request is for a class within timeit that allows you to test code inside a with block. It strikes me as being useful but there's only one response on the issue, albeit a positiv

Re: http://bugs.python.org/issue19495 timeit enhancement

2014-06-12 Thread Steven D'Aprano
On Fri, 13 Jun 2014 00:35:43 +0100, Mark Lawrence wrote: > The request is for a class within timeit that allows you to test code > inside a with block. It strikes me as being useful but there's only one > response on the issue, albeit a positive one. If others here think thi

http://bugs.python.org/issue19495 timeit enhancement

2014-06-12 Thread Mark Lawrence
The request is for a class within timeit that allows you to test code inside a with block. It strikes me as being useful but there's only one response on the issue, albeit a positive one. If others here think this would be a useful addition I'll see if I can take this forward, unl

Re: timeit module in IDLE

2013-03-14 Thread Chris Angelico
On Thu, Mar 14, 2013 at 6:21 PM, Terry Reedy wrote: > I believe everything in the doc should be in __all__. Open an issue on the > tracker and add terry.reedy as nosy. > Note on the issue that timeit.default_timer is not callable, contrary to the > doc (which should also be fixed). Thanks! Issue

Re: timeit module in IDLE

2013-03-14 Thread Terry Reedy
On 3/14/2013 2:58 AM, Chris Angelico wrote: While putting together some timing stats for the latest Python 3.3 string representation thread, I ran into an oddity in how IDLE handles timeit. The normal way to profile Python code, according to stuff I've found on the internet, is timeit.t

timeit module in IDLE

2013-03-14 Thread Chris Angelico
While putting together some timing stats for the latest Python 3.3 string representation thread, I ran into an oddity in how IDLE handles timeit. The normal way to profile Python code, according to stuff I've found on the internet, is timeit.timeit: >>> import timeit >>> ti

Re: Question about timeit

2011-07-22 Thread Frank Millman
On Jul 22, 2:43 pm, Thomas Jollans wrote: > On 22/07/11 14:30, Frank Millman wrote: > > > > > > > This is what I get after modifying timeit.py as follows - > > >     if args is None: > >         args = sys.argv[1:] > > +       print(args) > > &

Re: Question about timeit

2011-07-22 Thread Thomas Jollans
On 22/07/11 14:30, Frank Millman wrote: > This is what I get after modifying timeit.py as follows - > > if args is None: > args = sys.argv[1:] > + print(args) > > C:\>python -m timeit int(float('165.0')) > ["int(float('165.0

Re: Question about timeit

2011-07-22 Thread Frank Millman
at it just > evaluates the plain string itself instead of the code. > > Stefan- Hide quoted text - > > - Show quoted text - This is what I get after modifying timeit.py as follows - if args is None: args = sys.argv[1:] + print(args) C:\>python -m timeit int(floa

Re: Question about timeit

2011-07-22 Thread Stefan Behnel
Thomas Rachel, 22.07.2011 10:08: Am 22.07.2011 08:59 schrieb Frank Millman: My guess is that it is something to do with the console, but I don't know what. If I get time over the weekend I will try to get to the bottom of it. I would guess that in the first case, python (resp. timeit.py) gets

Re: Question about timeit

2011-07-22 Thread Thomas Rachel
Am 22.07.2011 08:59 schrieb Frank Millman: My guess is that it is something to do with the console, but I don't know what. If I get time over the weekend I will try to get to the bottom of it. I would guess that in the first case, python (resp. timeit.py) gets the intended code for execution:

Re: Question about timeit

2011-07-22 Thread Frank Millman
On Jul 22, 8:37 am, Stefan Behnel wrote: > Frank Millman, 22.07.2011 08:06: > > > > > > > I mentioned in a recent post that I noticed an inconsistency in timeit, and > > then reported that I must have made a mistake. > > > I have now identified my prob

Re: Question about timeit

2011-07-21 Thread Stefan Behnel
Frank Millman, 22.07.2011 08:06: I mentioned in a recent post that I noticed an inconsistency in timeit, and then reported that I must have made a mistake. I have now identified my problem, but I don't understand it. C:\Python32\Lib>timeit.py "int(float('165.0'))" 1

Question about timeit

2011-07-21 Thread Frank Millman
Hi all I mentioned in a recent post that I noticed an inconsistency in timeit, and then reported that I must have made a mistake. I have now identified my problem, but I don't understand it. C:\Python32\Lib>timeit.py "int(float('165.0'))" 10 loops, best

timeit function

2010-08-01 Thread Mag Gam
wondering if the timeit function would be helpful in my case. I was thinking to open a subprocess to run the Unix command 10 times (instead of 1 million times) and then do the average and then do the graph. Any thoughts about this? Is timeit the right tool for what I am trying to do? TIA... -- http

Re: Surprising timeit result

2009-10-26 Thread Steven D'Aprano
On Tue, 27 Oct 2009 04:36:12 +, John O'Hagan wrote: > I sometimes use timeit to see if it's better to check if something needs > doing, or to just do it anyway. This result was surprising: > > setup = 'd1 = {"a":0, "b":0}; d2 = {"a&q

Re: Surprising timeit result

2009-10-26 Thread John O'Hagan
On Tue, 27 Oct 2009, Paul Rubin wrote: > "John O'Hagan" writes: > > Timer('d1.update(d2)', setup).timeit() > > 2.6499271392822266 > > > > Timer('if d1 != d2: d1.update(d2)', setup).timeit() > > 1.0235211849212646 > >

Re: Surprising timeit result

2009-10-26 Thread Paul Rubin
"John O'Hagan" writes: > Timer('d1.update(d2)', setup).timeit() > 2.6499271392822266 > > Timer('if d1 != d2: d1.update(d2)', setup).timeit() > 1.0235211849212646 > > In other words, in this case it's substantially quicker to check

Surprising timeit result

2009-10-26 Thread John O'Hagan
I sometimes use timeit to see if it's better to check if something needs doing, or to just do it anyway. This result was surprising: setup = 'd1 = {"a":0, "b":0}; d2 = {"a":0, "b":1}' Timer('d1.update(d2)', setup).timeit() 2.64

Re: timeit and __future__

2009-06-20 Thread Steven D'Aprano
ld only come up with this: > > timeit.template = 'from __future__ import with_statement\n' + > timeit.template > > timeit should directly support importing __future__ stuff... Yes, it probably should. Please make a bug report/feature request at the Python bug tracker. If

timeit and __future__

2009-06-19 Thread Karl Chen
from __future__ import with_statement\n' + timeit.template timeit should directly support importing __future__ stuff... -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange interaction between timeit and recursion

2009-05-04 Thread Hrvoje Niksic
Steven D'Aprano writes: > I don't understand why my recursive function hits the recursion > limit inside the timeit.Timer when it works outside of it. Probably because your test function is at the very edge of the recursion limit, and timeit.Timer triggers it because it calls it at a deeper stac

Re: Strange interaction between timeit and recursion

2009-05-03 Thread Diez B. Roggisch
namekuseijin schrieb: Recursion is unpythonic. Do not use it. Since when? Says who? Lacking tail-recursion, it's not the choice for loops, but whatever algorithm is recursive can be written as such. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange interaction between timeit and recursion

2009-05-03 Thread Chris Rebert
On Sun, May 3, 2009 at 11:27 PM, namekuseijin wrote: > Recursion is unpythonic.  Do not use it. That's a tad extreme. I think the accepted practice is merely not to use recursion gratuitously. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange interaction between timeit and recursion

2009-05-03 Thread namekuseijin
Recursion is unpythonic. Do not use it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange interaction between timeit and recursion

2009-05-03 Thread Diez B. Roggisch
Steven D'Aprano schrieb: I'm seeing a strange interaction between timeit and recursion. sys.getrecursionlimit() 1000 from timeit import Timer setup = """def test(n=1): ... if n < 999: return test(n+1) ... return None ... """ exec setup

Strange interaction between timeit and recursion

2009-05-03 Thread Steven D'Aprano
I'm seeing a strange interaction between timeit and recursion. >>> sys.getrecursionlimit() 1000 >>> from timeit import Timer >>> setup = """def test(n=1): ... if n < 999: return test(n+1) ... return None ... """ >>>

Re: Timeit

2009-02-18 Thread Steven D'Aprano
On Wed, 18 Feb 2009 17:35:16 -0800, cokofreedom wrote: > I am really stuck trying to work out how to pass variables to timeit to > allow me to run any of the examples... setup = "from __main__ import example1, example2, example3" Timer("example1()", setup) In Py

Timeit

2009-02-18 Thread cokofreedom
I've having an annoying problem at the moment. I'm writing code for the travelling salesmen problem and comparing different techniques. But I've having a problem using timeit. I have a file called "testplatform.py" that contains 4 class: Test() - which is called first to

Re: Python time measure question (timeit)

2009-02-01 Thread Steve Holden
vedrandeko...@yahoo.com wrote: > On 1 velj, 17:42, Steve Holden wrote: >> vedrandeko...@yahoo.com wrote: >>> Hello, >>> When I run following code with os.popen (for this time measure I'm >>> using python module timeit): >>> for i i

Re: Python time measure question (timeit)

2009-02-01 Thread vedrandekovic
On 1 velj, 17:42, Steve Holden wrote: > vedrandeko...@yahoo.com wrote: > > Hello, > > > When I run following code with os.popen  (for this time measure I'm > > using python module timeit): > > > for i in range(50): > >     print i > > > I ge

Re: Python time measure question (timeit)

2009-02-01 Thread Steve Holden
vedrandeko...@yahoo.com wrote: > Hello, > > When I run following code with os.popen (for this time measure I'm > using python module timeit): > > > for i in range(50): > print i > > > I get this result: 0.00246958761519 > > > But w

Python time measure question (timeit)

2009-02-01 Thread vedrandekovic
Hello, When I run following code with os.popen (for this time measure I'm using python module timeit): for i in range(50): print i I get this result: 0.00246958761519 But when I run same code from IDLE i get this result: 6.4533341528e-005 now, I have two questions:

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
>> >> 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

Re: Passing function objects to timeit

2008-03-31 Thread Peter Otten
hose 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 pollution. >> >> > Thanks for the

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

Re: Passing function objects to timeit

2008-03-30 Thread George Sakkis
h > >> 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 pollution. > > > Thanks for the effort, but if that's the only solution, I think the > > solutio

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 changin

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

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. Tal

Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
arguments are provided to me as >> Python objects, but timeit requires strings. Converting the objects to >> strings is not practical, and the objects might not exist in the >> __main__ module. > > Ah, ok, I understand now. I think this is more-or-less what you want: [s

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()', &

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. Co

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 inst

Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
le: >> >> >> def factory(): >> def f(): >> return "spam" >> return f >> >> def main(): >> func = factory() >> return timeit.Timer('func()', 'from __main__ import func').timeit() > >

Re: Passing function objects to timeit

2008-03-29 Thread Gabriel Genellina
#x27;from __main__ import spam') > > > But now I find myself wanting to time a function that's not defined in > __main__. Here's a illustrative example: > > > def factory(): > def f(): > return "spam" > return f > > def main

Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
27;s a illustrative example: def factory(): def f(): return "spam" return f def main(): func = factory() return timeit.Timer('func()', 'from __main__ import func').timeit() But it doesn't work: >>> main() Traceback (most recent

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread 7stud
result = 20 + 2 > > def run(self): > > #do stuff > > aFunction() > > #do other stuff > > import timeit > > > t = timeit.Timer("d.aFunction()", "from __main__ import Dog; d = > > Dog()") > > print t.timeit() >

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread 7stud
result = 20 + 2 > > def run(self): > > #do stuff > > aFunction() > > #do other stuff > > import timeit > > > t = timeit.Timer("d.aFunction()", "from __main__ import Dog; d = > > Dog()") > > print t.timeit() >

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread [EMAIL PROTECTED]
On May 24, 12:41 pm, 7stud <[EMAIL PROTECTED]> wrote: > Actually, you can do this: > > class Dog(object): > def aFunction(self): > result = 20 + 2 > def run(self): > #do stuff > aFunction() > #do other stuff > import time

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread [EMAIL PROTECTED]
On May 24, 12:41 pm, 7stud <[EMAIL PROTECTED]> wrote: > Actually, you can do this: > > class Dog(object): > def aFunction(self): > result = 20 + 2 > def run(self): > #do stuff > aFunction() > #do other stuff > import time

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread 7stud
Actually, you can do this: class Dog(object): def aFunction(self): result = 20 + 2 def run(self): #do stuff aFunction() #do other stuff import timeit t = timeit.Timer("d.aFunction()", "from __main__ import Dog; d = Dog()") print t.timei

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread 7stud
On May 24, 11:30 am, 7stud <[EMAIL PROTECTED]> wrote: > On May 24, 9:36 am, "[EMAIL PROTECTED]" > > > > <[EMAIL PROTECTED]> wrote: > > Hi, > > > I am using timeit to time a global function like this > > > t = timeit.Timer("

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread 7stud
On May 24, 9:36 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > I am using timeit to time a global function like this > > t = timeit.Timer("timeTest()","from __main__ import timeTest") > result = t.timeit(); > > But

Re: How can I time a method of a class in python using Timeit

2007-05-24 Thread vasudevram
On May 24, 8:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > I am using timeit to time a global function like this > > t = timeit.Timer("timeTest()","from __main__ import timeTest") > result = t.timeit(); > > But

How can I time a method of a class in python using Timeit

2007-05-24 Thread [EMAIL PROTECTED]
Hi, I am using timeit to time a global function like this t = timeit.Timer("timeTest()","from __main__ import timeTest") result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self):

Re: Timing a function object versus timeit

2006-11-03 Thread Steven D'Aprano
On Fri, 03 Nov 2006 18:02:37 -0800, Carl Banks wrote: >>>> import timeit >>>> timeit.Timer("foo(1)","from __main__ import foo") > 1.1497418880462646 Well, that was scarily simple. Thank you. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Timing a function object versus timeit

2006-11-03 Thread Carl Banks
Steven D'Aprano wrote: > The timeit module is ideal for measuring small code snippets; I want to > measure large function objects. > > Because the timeit module takes the code snippet argument as a string, it > is quite handy to use from the command line, but it is less con

Timing a function object versus timeit

2006-11-03 Thread Steven D'Aprano
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy to use from the command line, but it is less convenient for timing large pieces of code or when working

Re: timeit module for comparing the performance of two scripts

2006-07-12 Thread Georg Brandl
3c273 wrote: > "John Machin" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> You appear to know what a switch is. I'm therefore surprised that you >> appear not to >> know that the convention is that any program that uses >> command-line switches should do something informative whe

Re: timeit module for comparing the performance of two scripts

2006-07-12 Thread Fredrik Lundh
"3c273" wrote: > Doh! Me thinks Windows at work "python /?" (No good!) that was supposed to be fixed in 2.5, but it doesn't seem to have made it into beta 2. hmm. -- http://mail.python.org/mailman/listinfo/python-list

Re: timeit module for comparing the performance of two scripts

2006-07-11 Thread 3c273
"John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > You appear to know what a switch is. I'm therefore surprised that you > appear not to > know that the convention is that any program that uses > command-line switches should do something informative when run with a -h > sw

Re: timeit module for comparing the performance of two scripts

2006-07-11 Thread John Machin
On 12/07/2006 6:35 AM, 3c273 wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> $ python -m timeit -s "import pyConfig" "pyConfig.pyConfig()" >> $ python -m timeit -s "import pyConparse" &q

Re: timeit module for comparing the performance of two scripts

2006-07-11 Thread John Machin
On 12/07/2006 1:33 AM, Phoe6 wrote: > Hi, Hi, I'm a little astonished that anyone would worry too much (if at all!) about how long it took to read a config file. Generally, one would concentrate on correctness, and legibility of source code. There's not much point IMHO in timing your pyConfig

Re: timeit module for comparing the performance of two scripts

2006-07-11 Thread 3c273
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > $ python -m timeit -s "import pyConfig" "pyConfig.pyConfig()" > $ python -m timeit -s "import pyConparse" "pyConparse.pyConParse()" > > note that

Re: timeit module for comparing the performance of two scripts

2006-07-11 Thread Fredrik Lundh
"Phoe6" >> $ python -m timeit -s "import pyConfig" "pyConfig.pyConfig()" >> $ python -m timeit -s "import pyConparse" "pyConparse.pyConParse()" > >> note that timeit runs the benchmarked function multiple times, so you may

  1   2   >