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 <landima...@gmail.com>
To: Mahmood Naderan <nt_mahm...@yahoo.com>
Cc: python mailing list <python-list@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_mahm...@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/



      
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to