[TriLUG] clock() from time.h

Rodney Radford rradford at mindspring.com
Thu May 18 14:08:55 EDT 2006


Yes, use time(NULL) both before and after the code you want to time, the difference in the two values is the number of elapsed seconds.  It will work the same under both Linux and Windows.

-----Original Message-----
>From: Warren Myers <volcimaster at gmail.com>
>Sent: May 18, 2006 2:02 PM
>To: Triangle Linux Users Group discussion list <trilug at trilug.org>
>Subject: Re: [TriLUG] clock() from time.h
>
>how about using time() - it returns the number of seconds elapsed since
>00:00 hours, Jan 1, 1970 UTC from the system clock.
>
>http://www.cplusplus.com/ref/ctime/time.html
>
>Warren
>
>On 5/18/06, Randall Barlow <randall_barlow at ncsu.edu> wrote:
>>
>> Rodney Radford wrote:
>> > The man page states that clock "returns an approximation of processor
>> time used by the program", which matches what you are getting under Linux.
>> However, this link, http://www.cygwin.com/ml/cygwin/2003-10/msg01086.html,
>> implies that under a Windows box clock actually returns the sum of the
>> user-used-time and the system-used-time - ie: wall clock time. Now that
>> doesn't answer your question of 'why', but does agree with what you are
>> seeing.  Perhaps the issue is that Windows doesn't differentiate between
>> windows and user time, or any time per process.
>> >
>> > Which did you want to see - system time or wall-clock time as perhaps
>> there is a better solution than using clock().
>> My intention was to see wall-clock time - do you know of something that
>> will give me this in both windows and linux?  If not, do you know
>> something that will under linux (and I can just use preprocessor
>> directives to check whether I am in Linux or Windows at compile time...)
>>
>> Randy
>>
>> --
>> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
>> TriLUG Organizational FAQ  : http://trilug.org/faq/
>> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
>>
>
>
>
>-- 
>http://warrenmyers.com
>"God may not play dice with the universe, but something strange is going on
>with the prime numbers." --Paul Erd?s
>"It's not possible. We are the type of people who have everything in our
>favor going against us." --Ben Jarhvi, Short Circuit 2




More information about the TriLUG mailing list