Brett W. McCoy wrote:
> 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
> 
> -- Brett

The timing of the program is probably correct despite it _appearing_ to 
take 5 seconds.  More than likely the program will have exited after .12 
-.15 seconds.  The rest of the time is probably the console playing 
"catch up" to the output of the program.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.0
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to