www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/11/00:33:54

Date: Tue, 10 Feb 1998 21:32:46 -0800 (PST)
Message-Id: <199802110532.VAA05864@adit.ap.net>
Mime-Version: 1.0
To: chojnack AT quantum DOT de, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: how to reset clock()

At 08:52  2/10/1998 +0100, Tom Chojnacki wrote:
>I want to measure time intervals in which some function executes itself.
>I used clock() function which returns time which elapsed since first
>call to clock(). But how can I reset the clock() to measure another time
>interval and not time since the first call again.
As far as I know, you can't. Your best bet is to save the value returned at
the start of the interesting time and subtract the value returned at the
end. i.e.:

        clock_t start_clock;
        start_clock = clock();
        /* Code */
        printf("Took %lu ticks\n", (unsigned long)clock() - start_clock);

>Are there any alternative time measuring functions which I could use ?.
Not that will do what you want. There is `gettimeofday', but it's more
complicated to use. Also, under other operating systems, it will give
different results. (`clock' measures CPU time used while `gettimeofday'
measures real time, but on single-tasking DOS they're the same.)

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019