|
From: Ioannis V. <no...@ho...> - 2002-05-13 22:23:55
|
clock_t clock(void); It returns the processor time that the program has
spent so far from the beginning of its execution.
clock()/CLOCKS_PER_SEC is that time in seconds (integer).
#include <iostream>
#include <ctime>
void useless()
{
for(int i=0; i<1024*1024*1024; i++)
;
}
int main()
{
using namespace std;
clock_t t1, t2;
for(int i=0; i<100*1024*1024; i++)
;
t1=clock();
cout<<"Time passed since the beginning of the program :"<<t1<<endl;
cout<<"In seconds: "<< t1/CLOCKS_PER_SEC<<endl;
t1=clock();
useless();
t2=clock();
cout<<"\nuseless() took "<<t2-t1<<" to complete\n";
cout<<"In seconds: "<<(t2-t1)/CLOCKS_PER_SEC<<endl;
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Christian Faulhammer
> Sent: Monday, May 13, 2002 10:23 PM
> To: dev...@li...
> Subject: [Dev-C++] System specific?
>
>
> Hi Ioannis,
>
> > For portable code use the functions provided in time.h .
> There is much
> > useful stuff in there.
> Good idea....if I could understand how to use it. The
> original function
> has been given to us by our teacher as a help...it's for
> three weeks now
> that I am in contact with C++. This routine should return a time (no
> matter which, but in seconds would be great), so I can
> measure the time
> passed from start to end of the task given to the user. Is there a
> portable solution or does the original function only work with gcc
> greater than 2.95.3 (perhaps gcc 3.x)?
> In the code I use MyTime as follows:
>
> ----------------------------8< schnipp------------------------------
> start=MyTime();
> [task]
> end=MyTime();
> complete=(end - start) + (10 * penaltycounter);
> ----------------------------schnapp >8------------------------------
>
> You understand what I want? ;)
>
> Chau
>
> V-Li
>
> _______________________________________________________________
>
> Have big pipes? SourceForge.net is looking for download
> mirrors. We supply
> the hardware. You get the recognition. Email Us:
> ban...@so...
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|