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.org/mai

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Ganesh Pal
Thank you , this answers my question : ) On Apr 22, 2015 6:39 PM, "Michael Torrie" wrote: > > On 04/21/2015 09:31 PM, Ganesh Pal wrote: > > Iam not able to understand what why only 10 loops were run ? what > > does this mean and how does this work ? > > I have a hunch you're mistakenly thinkin

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Ian Kelly
On Wed, Apr 22, 2015 at 7:07 AM, Michael Torrie wrote: > 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 te

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Michael Torrie
On 04/21/2015 09:31 PM, Ganesh Pal wrote: > Iam not able to understand what why only 10 loops were run ? what > does this mean and how does this work ? 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

Re: python : timeit - Tool for measuring execution time

2015-04-21 Thread Ben Finney
Ganesh Pal writes: > Iam running the below command on Linux machine have Python 2.7 > installed , If it hasn't already been said: You should be targeting Python 3 wherever possible (with the ‘python3’ command). Since you're not in this case – and you are specifically testing Python 2 features –

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 $ python -m timeit 'for i

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
eit 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.sinusLite(0.7)", "import test") t2 = timeit.Timer("y=math.sin(4.39)", "import math")

Re: Execution Time and Memory taken by the program

2014-07-23 Thread Irmen de Jong
On 23-7-2014 17:50, Orochi wrote: > I want a timer to calculate the execution time of the program > actually I am trying to solve problems on codechef.com and want to find out > the time and memory taken by the program to execute. > > I know we can import time.time() in unix and

Execution Time and Memory taken by the program

2014-07-23 Thread Orochi
I want a timer to calculate the execution time of the program actually I am trying to solve problems on codechef.com and want to find out the time and memory taken by the program to execute. I know we can import time.time() in unix and time.clock() in windows also there is a library timeit

Re: Best Way To Bound Function Execution Time

2011-12-31 Thread Paul Rubin
Tim Daneliuk writes: > Is there some standard Pythonic way to bound how long a function > call can run, after which time it is forcefully terminated? Basically, run it in a separate process and use os.kill to kill it. -- http://mail.python.org/mailman/listinfo/python-list

Best Way To Bound Function Execution Time

2011-12-31 Thread Tim Daneliuk
I am writing some paramiko-based ssh routines. One of them logs into a remote server and then does a sudo command. The problem is that if the user provides the incorrect sudo password, the call hangs the other end is waiting for the correct password to be entered. Is there some standard Pythoni

Re: using timers to force an execution time

2009-07-16 Thread superpollo
Nick Craig-Wood wrote: > ... import signal, os, time ... importing os is useless of course... -- http://mail.python.org/mailman/listinfo/python-list

Re: using timers to force an execution time

2009-07-16 Thread superpollo
Nick Craig-Wood wrote: superpollo wrote: > ... Or if you are on unix you can use signals... It is probably just about acceptable to raise an exception in a signal handler like this code does. > ... neat! -- http://mail.python.org/mailman/listinfo/python-list

Re: using timers to force an execution time

2009-07-16 Thread Paul Moore
2009/7/16 superpollo : > hello. > > based upon previuos suggestions, i tried to write a program in which i would > like to have a certain code fragment to execute only for a specified amount > of time (say 3 seconds), then bail out. > > but i get the following: > > $ cat tmr004.py > #!/usr/bin/pyth

Re: using timers to force an execution time

2009-07-16 Thread Nick Craig-Wood
superpollo wrote: > Diez B. Roggisch wrote: > > superpollo wrote: > >>am i wrong? > > > > > > No, you are right, for threads that is. You can try & trick around with the > > trace-functionality of python, and some ctypes-based > > system-thread-module-tricks that are, as mentioned before, black

Re: using timers to force an execution time

2009-07-16 Thread superpollo
Diez B. Roggisch wrote: superpollo wrote: am i wrong? No, you are right, for threads that is. You can try & trick around with the trace-functionality of python, and some ctypes-based system-thread-module-tricks that are, as mentioned before, black-magic & a spinning gatling gun pointed to you

Re: using timers to force an execution time

2009-07-16 Thread Diez B. Roggisch
superpollo wrote: > Diez B. Roggisch wrote: >> superpollo wrote: >>>see? the while body ran for about 7 seconds... i bet it has to do with >>>the fact that the timer does not control inner loops... any suggestion? >> >> >> Of course the inner loop isn't affected by the set event - how should it

Re: using timers to force an execution time

2009-07-16 Thread superpollo
Diez B. Roggisch wrote: superpollo wrote: see? the while body ran for about 7 seconds... i bet it has to do with the fact that the timer does not control inner loops... any suggestion? Of course the inner loop isn't affected by the set event - how should it be, if you don't check it. if you

Re: using timers to force an execution time

2009-07-16 Thread Diez B. Roggisch
Diez B. Roggisch wrote: > superpollo wrote: > >> hello. >> >> based upon previuos suggestions, i tried to write a program in which i >> would like to have a certain code fragment to execute only for a >> specified amount of time (say 3 seconds), then bail out. >> >> but i get the following: >>

Re: using timers to force an execution time

2009-07-16 Thread superpollo
Diez B. Roggisch wrote: What you can't achieve in python without major black magic hackery that is very dangerous is to terminate a thread while it is executing. Termination has to be co-operative. i see. thanks a lot. bye -- http://mail.python.org/mailman/listinfo/python-list

Re: using timers to force an execution time

2009-07-16 Thread Diez B. Roggisch
superpollo wrote: > hello. > > based upon previuos suggestions, i tried to write a program in which i > would like to have a certain code fragment to execute only for a > specified amount of time (say 3 seconds), then bail out. > > but i get the following: > > $ cat tmr004.py > #!/usr/bin/pytho

Re: using timers to force an execution time

2009-07-16 Thread Xavier Ho
On Thu, Jul 16, 2009 at 6:34 PM, superpollo wrote: > hello. > > based upon previuos suggestions, i tried to write a program in which i > would like to have a certain code fragment to execute only for a specified > amount of time (say 3 seconds), then bail out. > > > see? the while body ran for

using timers to force an execution time

2009-07-16 Thread superpollo
hello. based upon previuos suggestions, i tried to write a program in which i would like to have a certain code fragment to execute only for a specified amount of time (say 3 seconds), then bail out. but i get the following: $ cat tmr004.py #!/usr/bin/python -u import threading , time e =

RE: Multiprocessing takes higher execution time

2009-01-08 Thread Sibtey Mehdi
Thanks Nick. It processes 10-15 projects(i.e. 10-15 processes are started) at once. One Zip file size is 2-3 MB. When I used dual core system it reduced the execution time from 61 seconds to 55 seconds. My dual core system Configuration is, Pentium(R) D CPU 3.00GHz, 2.99GHz 1 GB RAM Regards

Re: Multiprocessing takes higher execution time

2009-01-08 Thread James Mills
On Thu, Jan 8, 2009 at 7:31 PM, Nick Craig-Wood wrote: (...) > How many projects are you processing at once? And how many MB of zip > files is it? As reading zip files does lots of disk IO I would guess > it is disk limited rather than anything else, which explains why doing > many at once is a

Re: Multiprocessing takes higher execution time

2009-01-08 Thread Nick Craig-Wood
Sibtey Mehdi wrote: > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) > I create a process, > > Process(target=compare, args=(oldFile, newFile)).start() > > It takes 61 seconds execution

RE: Multiprocessing takes higher execution time

2009-01-07 Thread Sibtey Mehdi
higher execution time On 2009-01-07, Steve Holden wrote: >> I use multiprocessing to compare more then one set of files. >> >> For comparison each set of files (i.e. Old file1 Vs New file1) >> I create a process, >> >> Process(target=compare, args=(oldFile,

Re: Multiprocessing takes higher execution time

2009-01-07 Thread Nick Craig-Wood
;> Process(target=compare, args=(oldFile, newFile)).start() > >> > >> It takes 61 seconds execution time. > >> > >> When I do the same comparison without implementing > >> multiprocessing, it takes 52 seconds execution time. > > > My first sugg

Re: Multiprocessing takes higher execution time

2009-01-07 Thread Grant Edwards
>> >> It takes 61 seconds execution time. >> >> When I do the same comparison without implementing >> multiprocessing, it takes 52 seconds execution time. > My first suggestion would be: show us some code. We aren't > psychic, you know. I am! He's only

Re: Multiprocessing takes higher execution time

2009-01-07 Thread Steve Holden
Sibtey Mehdi wrote: > Hi, > > > > I use multiprocessing to compare more then one set of files. > > For comparison each set of files (i.e. Old file1 Vs New file1) I create > a process, > > Process(target=compare, args=(oldFile, newFile)).start() > >

Multiprocessing takes higher execution time

2009-01-07 Thread Sibtey Mehdi
Hi, I use multiprocessing to compare more then one set of files. For comparison each set of files (i.e. Old file1 Vs New file1) I create a process, Process(target=compare, args=(oldFile, newFile)).start() It takes 61 seconds execution time. When I do the same comparison without

Re: execution time

2008-12-14 Thread Steven D'Aprano
r i in range(5)] print "random data : >> %s" % data >> print "result: %s" %bucket2.sort(data) >> >> How to write a test script which will outputs execution time for >> bucket2.sort(data) ? > > Well: > > import time > > star

Re: execution time

2008-12-14 Thread Andreas Kostyrka
bucket2.sort(data) > > How to write a test script which will outputs execution time for > bucket2.sort(data) ? Well: import time starttime = time.time() endtime = time.time() print "Whatever does, it took %5.3fs to do." % (endtime - starttime) Alternativly take a

Re: execution time

2008-12-14 Thread Bruno Desthuilliers
David Hláčik a écrit : Hi guys, #! /usr/bin/python import random import bucket2 data = [ random.randint(1,25) for i in range(5)] print "random data : %s" % data print "result: %s" %bucket2.sort(data) How to write a test script which will outputs execution time for bucket2

execution time

2008-12-14 Thread David Hláčik
Hi guys, #! /usr/bin/python import random import bucket2 data = [ random.randint(1,25) for i in range(5)] print "random data : %s" % data print "result: %s" %bucket2.sort(data) How to write a test script which will outputs execution time for bucket2.sort(data) ? Thanks

Re: Different execution time in python code between embedded or standalone

2008-06-08 Thread Pau Freixes
HI list, I found the problem guys, when I embedded python code didn't call to PyEval_InitThreads(); This function initialize GIL and other data structures for do a python code thread safe. I believe the python traditional ( python name_script.py ) run always a thread safe interpreter. Therefore,

Re: Different execution time in python code between embedded or standalone

2008-06-04 Thread Pau Freixes
Hi Gabriel, The source code for embedded mode it's the same, look this code : _nrdigest = 0 _const_b = 20 _f = None _signal = False def handler_alrm(signum, frame): global _signal global _nrdigest global _f _signal = True def try_me(): global _nrdigest global _f g

Re: Different execution time in python code between embedded or standalone

2008-06-03 Thread Gabriel Genellina
En Tue, 03 Jun 2008 16:58:12 -0300, Pau Freixes <[EMAIL PROTECTED]> escribió: Hi list, First Hello to all, this is my and hope not end message to the list :P This last months I have been writting a program in c like to mod_python for embedding python language, it's a middleware for dispat

Different execution time in python code between embedded or standalone

2008-06-03 Thread Pau Freixes
Hi list, First Hello to all, this is my and hope not end message to the list :P This last months I have been writting a program in c like to mod_python for embedding python language, it's a middleware for dispatch and execute python batch programs into several nodes. Now I'm writing some python

Re: Execution time of lines within a function

2006-12-07 Thread Ed Leafe
On Dec 4, 2006, at 11:36 PM, Paul McGuire wrote: > The PythonDecoratorLibrary page on the Python wiki has a link to a > @profile > decorator, that I have used to profile the contents of targeted > functions > (only just now, I don't seem to be able to get to the wiki to get > the exact > lin

Re: Execution time of lines within a function

2006-12-04 Thread Paul McGuire
"monkeyboy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I have a function that hotshot says is very slow. I can get the > aggregate execution time, but is there a way to get the execution time > of each line so I can find the b

Re: Execution time of lines within a function

2006-12-04 Thread monkeyboy
The output was from print_callees(). It appears as though print_stats() and print_callees() return the same data, just in a different orangization. There is supposed to be a "lineevents=1" option in hotshot.Profile, for line timings, but it doesn't seem to work in Python 2.4. Thanks for your help

Re: Execution time of lines within a function

2006-12-04 Thread Neil Cerutti
On 2006-12-04, monkeyboy <[EMAIL PROTECTED]> wrote: > Thanks Neil, > > I looked at that, but maybe I don't understand the output. I > was hoping to see the cummulative time for the function and > then the time associated with each statement (line) within the > function. > > Any suggestions? I don'

Re: Execution time of lines within a function

2006-12-04 Thread monkeyboy
is very slow. I can get the > > aggregate execution time, but is there a way to get the > > execution time of each line so I can find the bottleneck? > > Try 'print_callees' on the stats object for your bottleneck. That > may help. > > -- > Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Execution time of lines within a function

2006-12-04 Thread Neil Cerutti
On 2006-12-04, monkeyboy <[EMAIL PROTECTED]> wrote: > I have a function that hotshot says is very slow. I can get the > aggregate execution time, but is there a way to get the > execution time of each line so I can find the bottleneck? Try 'print_callees' on the stats o

Execution time of lines within a function

2006-12-04 Thread monkeyboy
Hello, I have a function that hotshot says is very slow. I can get the aggregate execution time, but is there a way to get the execution time of each line so I can find the bottleneck? Thank you -- http://mail.python.org/mailman/listinfo/python-list

Re: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Grant Edwards wrote: >> You can get better resolution by using time.clock() instead of >> time.time(). > > Oh really? When I do it, time.clock() is worse: on Unix, time.clock() is a tick counter; if your process is running when the tick interrupt arrives, the internal counter value is increment

Re: How to measure execution time of a program

2006-06-28 Thread Grant Edwards
On 2006-06-28, Pete Forman <[EMAIL PROTECTED]> wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> writes: > > simplest way: > > > > t0 = time.time() > > You can get better resolution by using time.clock() instead of > time.time(). Oh really? When I do it, time.clock() is worse: ---

Re: How to measure execution time of a program

2006-06-28 Thread Wolfram Kraus
On 28.06.2006 10:01, Girish Sahani wrote: > Sorry for spamming again, but please also enlighten me with some way to > time a function i.e. to find out how much time each function takes for > execution in a big program. >> Hi all, >> >> Can anyone tell me the simplest way to do it (some code snipp

Re: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Pete Forman wrote: > > t0 = time.time() > > You can get better resolution by using time.clock() instead of > time.time(). depends on the platform, and whether you want wall time or process time. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to measure execution time of a program

2006-06-28 Thread Pete Forman
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > simplest way: > > t0 = time.time() You can get better resolution by using time.clock() instead of time.time(). -- Pete Forman-./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does no

Re: How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Sorry for spamming again, but please also enlighten me with some way to time a function i.e. to find out how much time each function takes for execution in a big program. > Hi all, > > Can anyone tell me the simplest way to do it (some code snippet that > could be included in the program's main f

Re: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Girish Sahani wrote: > Can anyone tell me the simplest way to do it (some code snippet that > could be included in the program's main function) ?? simplest way: t0 = time.time() main() print time.time() - t0, "seconds" (assuming that you want to measure wall time, and that your prog

How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Hi all, Can anyone tell me the simplest way to do it (some code snippet that could be included in the program's main function) ?? Thanks, girish -- http://mail.python.org/mailman/listinfo/python-list

Re: python profiling, hotspot and strange execution time

2005-09-08 Thread bdrosen96
ist processing, but also some "simple" computation such > as basic linear algebra involved. I would like to speed things up > implementing some of the functions in C. So I need profiling. > >I first tried to use the default python profiler, but profiling my > application mu

Re: python profiling, hotspot and strange execution time

2005-09-08 Thread Jeremy Jones
he wall clock and profile time difference to the >>overhead of hotshot. While hotshot is miles better than the "regular" >>profiler, it can still take a little time to profile code. >> >> > >Well, if hotshot reported a timing which is longer than the ex

Re: python profiling, hotspot and strange execution time

2005-09-08 Thread cournape
me :) I understand the difference between CPU time and time spent in the python code (even if I was not clear in my previous post about it...). But this case does not apply to my code, as my code is never "idled", takes 100 % of the cpu, with no other CPU consuming task > I would att

Re: python profiling, hotspot and strange execution time

2005-09-06 Thread Jeremy Jones
he functions in C. So I need profiling. > > I first tried to use the default python profiler, but profiling my >application multiplies the execution time by a factor between 10 and >100 ! So I decided to give a try to hotspot. > OK - first of all, as someone else has asked, what pl

Re: python profiling, hotspot and strange execution time

2005-09-06 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, [EMAIL PROTECTED] writes >Hi there, > > I have some scientific application written in python. There is a >good deal of list processing, but also some "simple" computation such >as basic linear algebra involved. I would like to speed things up >implementing some of

Re: python profiling, hotspot and strange execution time

2005-09-06 Thread Paul Rubin
[EMAIL PROTECTED] writes: >I have some scientific application written in python. There is a > good deal of list processing, but also some "simple" computation such > as basic linear algebra involved. I would like to speed things up > implementing some of the functions in C. So I need profiling.

python profiling, hotspot and strange execution time

2005-09-06 Thread cournape
t tried to use the default python profiler, but profiling my application multiplies the execution time by a factor between 10 and 100 ! So I decided to give a try to hotspot. I just followed the example of the python library reference, but I have some strange results concerning cpu time. My profiling

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Carl Banks wrote: > I could, however, see myself > using the slightly more complicated descriptor such as this (for a > wholly different reason, though): > > . def call_with_open_file(filename): > . def descriptor(func): > . flo = open(filename) > . try: f(flo) > . fi

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Nick Coghlan wrote: > Anyway, if others agree that the ability to execute a suite at def exeuction > time to preinitialise a function's locals without resorting to bytecode hacks is > worth having, finding a decent syntax is the next trick :) Workarounds: 1. Just use a freaking global, especially

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Bengt Richter
On Fri, 25 Feb 2005 19:34:53 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Nick Coghlan wrote: >> Anyway, if others agree that the ability to execute a suite at def >> exeuction time to preinitialise a function's locals without resorting to >> bytecode hacks is worth having, finding a decent

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Steven Bethard wrote: Worth looking at is the thread: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/58f53fe8bcc49664/ Huh - I thought I put something in the original post saying "without resorting to bytecode hacks", but I must have deleted it before sending the messag

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Steven Bethard
Nick Coghlan wrote: Anyway, if others agree that the ability to execute a suite at def exeuction time to preinitialise a function's locals without resorting to bytecode hacks is worth having, finding a decent syntax is the next trick :) I'm not certain how many use cases really require a full su

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
ce at compile time. D'oh - "definition execution time", not compile time. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mai

Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Steven Bethard wrote: So just to clarify, the issue you're trying to address is when you want early binding like function default arguments get, but you don't want to declare the names as function arguments? Basically, yeah. Although I later realised I got the name of the feature I want wrong -