July 15th, 2005, 02:39 AM
-
how can i calculate time to run a task ???
how can i calculate the time to run my function in Python? Can you help me, thanks .
July 15th, 2005, 03:35 AM
-
Hi!
Code:
import time
def your_function():
# whatever your function does
loops = 10000 # how often your function is called
begin = time.time()
for x in range(loops):
your_function()
print "%0.3fs" % (time.time() - begin)
Regards, mawe
July 15th, 2005, 07:41 AM
-
yes and to give alittle feedback...
mutliply the total time for one function timing times the number you want to run it and then you have the total time left if you subtract the time you already did....
Those people who think they know everything are a great annoyance to those of us who do.
July 15th, 2005, 08:20 AM
-
monkeyman, maybe it's because english is not my mother tongue, but I have no idea what you mean
July 15th, 2005, 10:59 AM
-
Okay I meant that your way is to see how long it takes to run all of them and mine is how long it takes to run one and then calculate the rest of the time or something like that...
I am not mother tongue either
Code:
>>> def func(times,function,*args):
start = time.clock()
function(args)
end = time.clock()
Time = "%f" % (end - start)
print str(float(Time)*times)+"s"
Thats my code for this thing and I did not run all of them I only ran it once...
It probably does not work to great not very accurate but i hope you get my point...
Last edited by monkeyman23555; July 15th, 2005 at 11:16 AM.
Those people who think they know everything are a great annoyance to those of us who do.
July 17th, 2005, 07:08 PM
-
I would also suggest using time.time() instead of time.clock() for improved compatibility between platforms. It also give better results IMO and is easier to understand
.
Mark.
Comments on this post
July 17th, 2005, 11:20 PM
-
Originally Posted by netytan
I would also suggest using time.time() instead of time.clock() for improved compatibility between platforms. It also give better results IMO and is easier to understand

.
Mark.
Not only that.. but time.time( ) works alot faster then time.clock( ) as they are for different purpose's
July 18th, 2005, 01:37 AM
-
July 18th, 2005, 02:16 PM
-
hi about the time.clock I just used it because the other time.time did not work???
I don't know why...
Those people who think they know everything are a great annoyance to those of us who do.