get the time needed to process one function.

G

George Orwell

daffyduck said:
is possible to get in seconds with a precision of 0.0000 the time get
by one function ?
i check clock() but im getting 0 with this:

1 #include <stdio.h>
2 #include <time.h>
3
4 int
5 main(){
6 float time1, time2;
7 int a;
8 time1 = clock();
9 for(a=0;a<100; a++){
10 printf("a");
11 }
12 time2 = clock();
13 printf("seconds: %f\n",((float)tempo2 - (float)tempo1) /
CLOCKS_PER_SEC);
14 }

Hi, buddy. How you doing?

That's because the division by CLOCKS_PER_SEC, by definition,
is calculating the number of seconds elapsed between the two
points.

The C standard doesn't specify a particular resolution, and you
can't even examine the value of CLOCKS_PER_SEC to determine the
particular resolution used.

In fact, you're not even guaranteed a return value from clock(),
which could return (clock_t)(-1) if the processor time isn't
available.

You have some options available.

1. You can use a profiling tool if you have one available. For
example, gcc has a -pg compilation option that produces an output
file for gprof, the GNU profiler. I believe the resolution for
that is still pretty limited, though.

2. You can tell us what platform you're on, and some people here
would be more than happy to indicate a platform-specific system
call for your system. If you choose this option, you may want
to cross-post to a platform-specific newsgroup as well as
comp.lang.c, otherwise you'll get a lot of troll replies.

I hope this has been of some help to you. Have a good
night. :)

Yours,
Han from China


Il mittente di questo messaggio|The sender address of this
non corrisponde ad un utente |message is not related to a real
reale ma all'indirizzo fittizio|person but to a fake address of an
di un sistema anonimizzatore |anonymous system
Per maggiori informazioni |For more info
https://www.mixmaster.it
 
I

Ian Collins

George said:
That's because the division by CLOCKS_PER_SEC, by definition,
is calculating the number of seconds elapsed between the two
points.
So? The OP is using floats.
The C standard doesn't specify a particular resolution, and you
can't even examine the value of CLOCKS_PER_SEC to determine the
particular resolution used.
Why not?
 
C

CBFalconer

Ian said:
George Orwell wrote:
.... snip ...


Why not?

I see no reason.

7.23.2.1 The clock function

Synopsis

[#1]
#include <time.h>
clock_t clock(void);

Description

[#2] The clock function determines the processor time used.

Returns

[#3] The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in
seconds, the value returned by the clock function should be
divided by the value of the macro CLOCKS_PER_SEC. If the
processor time used is not available or its value cannot be
represented, the function returns the value (clock_t)-1.
 
I

Ian Collins

CBFalconer said:
I see no reason.
Even though it appears incapable of replying on the correct sub-thread,
"Han's" explanation was valid. The resolution of clock() does not have
to match CLOCKS_PER_SEC.
 
C

CBFalconer

Ian said:
Even though it appears incapable of replying on the correct
sub-thread, "Han's" explanation was valid. The resolution of
clock() does not have to match CLOCKS_PER_SEC.

Aha. I read your original as meaning you couldn't examine the
value of CLOCKS_PER_SEC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top