Re: [Dev-C++] Does the result of my called clock() is wrong?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-07-09 13:48:23
|
clock returns amount of time consumed by your process. Obviously the first
call to clock() should be zero since your program hasn't done anything
yet.
When you write empty for() loops - without any actual work in them - the
compiler optimization will completely remove your loop. The result is that
your second call to clock() will be made immediately after the first call,
and give the value zero.
Try adding something interesting in your loop, to get your program to
work.
/Per W
On Fri, 9 Jul 2004, [gb2312] Bruce.J Sam wrote:
> The below program is just my simple test for clock( ).I use a nestin=
g "for" sentence to consume time.But it seem that the clock( ) doesn't work=
=2EThe t1 and t2 are all zero.Why the result is in this way?Perhaps my comp=
rehension in clock( ) is wrong.Can anyone give an example about using clock=
( )?
> /* ********************************* */
> #include <stdio.h>
> #include <time.h>
>
> main()
> {
> /*
> time_t biggest =3D 0x7FFFFFFF;
> printf("biggest =3D %s \n", ctime(&biggest));
> system("PAUSE");
> */
> int i, j;
> clock_t t1, t2;
>
>
> t1 =3D clock() / CLOCKS_PER_SEC;
> printf("t1 =3D %d\n", t1);
> for (i =3D 0; i < 9999; i++)
> for (j =3D 0; j < 9999; j++)
> ;
> t2 =3D clock() / CLOCKS_PER_SEC;
> printf("t2 =3D %d\n", t2);
> system("PAUSE");
> }
> /* *************************** */
> The result is :
> t1 =3D 0
> t2 =3D 0
>
>
>
> ---------------------------------
> Do You Yahoo!?
> 100=D5=D7=D3=CA=CF=E4=B9=BB=B2=BB=B9=BB=D3=C3=A3=BF=D1=C5=BB=A2=B5=E7=D3=
=CA=D7=D4=D6=FA=C0=A9=C8=DD=A3=A1
|