measuring a function time

Mahmood Naderan nt_mahmood at yahoo.com
Thu Jul 29 09:38:08 EDT 2010


Thanks, the first method worked. However clock() doesn't.

tic = time.time()
time.sleep( 2 )
toc = time.time()
print toc - tic
 
Result: 2.00269889832

>Take a look at time.clock()
tic = time.clock()
time.sleep( 2 )
toc = time.clock()
print toc - tic
 
result: 0.0

>More importantly, the above technique is acceptable if function() is very 
>long-running (multiple seconds, at least). 
yes, the code is long running.

Thanks
// Naderan *Mahmood;




________________________________
From: Matteo Landi <landimatte at gmail.com>
To: Mahmood Naderan <nt_mahmood at yahoo.com>
Cc: python mailing list <python-list at python.org>
Sent: Thu, July 29, 2010 5:12:58 PM
Subject: Re: measuring a function time

This should be enough

>>>import time
>>>tic = time.time()
>>>function()
>>>toc = time.time()
>>>print toc - tic

On Thu, Jul 29, 2010 at 2:34 PM, Mahmood Naderan <nt_mahmood at yahoo.com> wrote:
> Hi,
> I want to measure a function run time. I read
> http://docs.python.org/library/time.html but I am confused and don't know
> which one is suitable. I don't know is daylight timing important or not....
> or is Y2K issue important for my case or not.... I also don't know how epoch
> time is related to my work.
>
> I just want to do this (pseudocode):
> start_time = get_current_time;
> function();
> end_time = get_current_time;
> print (end_time - start_time)
>
> the output should be 7600 (s) for example. What is the best and easiest way
> to do that?
>
> Thanks,
>
> // Naderan *Mahmood;
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Matteo Landi
http://www.matteolandi.net/



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100729/40a1ba4c/attachment.html>


More information about the Python-list mailing list