On 7/6/07, snowet2000 <[EMAIL PROTECTED]> wrote:

> #include <stdio.h>
> #include <time.h>
> main()
> {
>    int i;
>    clock_t start,end;
>    double elapsed;
>
>    start=clock();
>    for(i=0;i<=100000;i++){
>       printf("Test!\n");
>    }
>    end=clock();
>    elapsed=((double)(end-start))/CLOCKS_PER_SEC;
>    printf("Elapsed time = %.12lf[sec]\n",elapsed);
>    printf("In clock ticks : %lf\n",end-start);
>    printf("CLOCKS_PER_SEC = %d\n",CLOCKS_PER_SEC);
> }
> --------------------------------------------------------------------
> .
> When I executed this program, I got the following result:
> --------------------------------------------------------------------
> ...
> Test!
> Test!
> Test!
> Elapsed time = 0.120000000000[sec]
> In clock ticks : 0.120000
> CLOCKS_PER_SEC = 1000000
> --------------------------------------------------------------------
> .
> It's strange that I could count about 5 seconds until the final
> "Test!" was appeared on the display...

Your counting is going to be different than what the CPU counts. I
usually got around 140000- 150000 for an elapsed count. Certainly less
than a single second. You can also use the time command-line tool to
get an idea of time usage Linxu reports back. You'll get something
like this (I fixed your code a little bit):

$ time clocktest
...
test!
test!
test!
start = 0
end = 140000
Elapsed time = 0.140000 [sec]
In clock ticks : 140000

real    0m0.698s
user    0m0.017s
sys     0m0.137s

> I don't know why the elapsed time in second is equal to that in
> clock ticks.

You should use %d there.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to