|
From: <v-...@ou...> - 2002-05-13 17:05:55
|
Hello,
In university I am doing a programming course and last week we had an
excercise using a given function to measure time:
----------------------------8< schnipp------------------------------
double MyTime() {
struct timeval Tp;
gettimeofday (&Tp, NULL);
return Tp.tv_sec + (Tp.tv_usec /10000000.);
}
----------------------------schnapp >8------------------------------
At home I wanted to finish the program using Dev-C++ (current beta with
fixed exe), but the compiler refused work when compiling this function
with the message
----------------------------8< schnipp------------------------------
aggregate `struct timeval Tp' has incomplete type and cannot be
initialized
----------------------------schnapp >8------------------------------
But in university (under Linux) it does work....so is this a problem of
the compiler (gcc versions differ in university and at home) or a
platform problem (Linux specific parts)? Sorry, I am no expert, just had
two weeks of this course and I am only used to basic (under DOS).
Chau
V-Li
|
|
From: Hongli L. <h....@ch...> - 2002-05-13 17:56:37
|
On Mon, 2002-05-13 at 18:45, Christian Faulhammer wrote:
> Hello,
>
> In university I am doing a programming course and last week we had an
> excercise using a given function to measure time:
>
> ----------------------------8< schnipp------------------------------
> double MyTime() {
> struct timeval Tp;
> gettimeofday (&Tp, NULL);
> return Tp.tv_sec + (Tp.tv_usec /10000000.);
> }
> ----------------------------schnapp >8------------------------------
>
> At home I wanted to finish the program using Dev-C++ (current beta with
> fixed exe), but the compiler refused work when compiling this function
> with the message
>
> ----------------------------8< schnipp------------------------------
> aggregate `struct timeval Tp' has incomplete type and cannot be
> initialized
> ----------------------------schnapp >8------------------------------
>
> But in university (under Linux) it does work....so is this a problem of
> the compiler (gcc versions differ in university and at home) or a
> platform problem (Linux specific parts)? Sorry, I am no expert, just had
> two weeks of this course and I am only used to basic (under DOS).
>
> Chau
>
I believe you need tin #include <sys/time.h>
|
|
From: <v-...@ou...> - 2002-05-13 19:25:55
|
Hi Hongli,
>> ----------------------------8< schnipp------------------------------
>> double MyTime() {
>> struct timeval Tp;
>> gettimeofday (&Tp, NULL);
>> return Tp.tv_sec + (Tp.tv_usec /10000000.);
>> }
>> ----------------------------schnapp >8------------------------------
> I believe you need tin #include <sys/time.h>
As I stated: Under Linux it does compile, and time.h is included, so
this should be no problem. Below a list of all included header files.
#include <iostream>
using std::cout; using std::cin;
#include <cstdlib>
using std::rand; using std::srand;
#include <sys/time.h>
#include <cmath>
using std::fmod;
#include <iomanip>
using std::setprecision;
Chau
V-Li
|
|
From: Ioannis V. <no...@ho...> - 2002-05-13 18:37:22
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Christian Faulhammer
> Sent: Monday, May 13, 2002 7:45 PM
> To: To: dev...@li...
> Subject: [Dev-C++] System specific?
>
>
> Hello,
>
> In university I am doing a programming course and last week we had an
> excercise using a given function to measure time:
>
> ----------------------------8< schnipp------------------------------
> double MyTime() {
> struct timeval Tp;
> gettimeofday (&Tp, NULL);
> return Tp.tv_sec + (Tp.tv_usec /10000000.);
> }
> ----------------------------schnapp >8------------------------------
>
> At home I wanted to finish the program using Dev-C++ (current
> beta with
> fixed exe), but the compiler refused work when compiling this function
> with the message
>
> ----------------------------8< schnipp------------------------------
> aggregate `struct timeval Tp' has incomplete type and cannot be
> initialized
> ----------------------------schnapp >8------------------------------
>
> But in university (under Linux) it does work....so is this a
> problem of
> the compiler (gcc versions differ in university and at home) or a
> platform problem (Linux specific parts)? Sorry, I am no
> expert, just had
> two weeks of this course and I am only used to basic (under DOS).
For portable code use the functions provided in time.h . There is much
useful stuff in there.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: <v-...@ou...> - 2002-05-13 20:25:54
|
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=3DMyTime(); [task] end=3DMyTime(); complete=3D(end - start) + (10 * penaltycounter); ----------------------------schnapp >8------------------------------ You understand what I want? ;) Chau V-Li |
|
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
>
|
|
From: <v-...@ou...> - 2002-05-15 16:16:01
|
Hi Ioannis, > clock_t clock(void); It returns the processor time that the program > has spent so far from the beginning of its execution. Ok, that would do, thank you very much.... Chau V-Li |