Re: clock() problem - measuring cycles
From: Robert B. Clark (epynex_at_3pynexf.pbz)
Date: 01/12/05
- Next message: ranjeet: "Any comments ??"
- Previous message: Francis Glassborow: "Re: Very Newbe question."
- Maybe in reply to: void: "Re: clock() problem - measuring cycles"
- Next in thread: B. v Ingen Schenau: "Re: clock() problem - measuring cycles"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Jan 2005 11:42:27 -0500
On Wed, 12 Jan 2005 00:52:03 -0800, "Ufit"
<kot_tmp0SPAMSPAM@NOpoczta.fm> wrote:
>I must precisely measure the time of calculation.
>f.ex
>
>clock_t begin,finish,time;
>begin=clock();
>Calculations();
>finish=clock();
>time=finish-begin;
>
>but unfortunatelly finish is equal to begin
>sth like begin=56789 and finish=56789
>they give me 0. How else can I measure the time very precisely?
The short answer is that you can't, at least not in a portable fashion.
This is a very platform-dependent thing to do.
See the c.l.c FAQ, question 19.37:
How can I implement a delay, or time a user's response, with sub-second
resolution?
http://www.eskimo.com/~scs/C-faq/q19.37.html
Of course, you could always loop your calculations by some arbitrarily
large number of iterations, and take the elapsed time for the entire
process divided by the number of loops::
#define ITERATIONS 1000000UL
clock_t t0, t1, elapsed;
unsigned long i;
t0 = clock();
for (i = 0; i < ITERATIONS; i++)
Calculations();
t1 = clock();
elapsed = t1 - t0;
printf("CLOCKS_PER_SEC is %f\n", CLOCKS_PER_SEC);
printf("Total elapsed time: %ld ticks (%f sec).\n",
elapsed, elapsed / CLOCKS_PER_SEC);
printf("Elapsed time per calc is %.2e seconds.\n",
elapsed / CLOCKS_PER_SEC / ITERATIONS);
This may not be desirable in your application for any number of
reasons--the least of which is the lack of precision your platform may
afford you.
You might want to post your question in a newsgroup that is more focused
upon your particular environment, as the means to achieve your goal will
necessarily involve the use of non-standard extensions to the C
language.
-- Robert B. Clark (email ROT13'ed) Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/
- Next message: ranjeet: "Any comments ??"
- Previous message: Francis Glassborow: "Re: Very Newbe question."
- Maybe in reply to: void: "Re: clock() problem - measuring cycles"
- Next in thread: B. v Ingen Schenau: "Re: clock() problem - measuring cycles"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|