-5
#ifdef WIN32
#else
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <conio.h>
#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
#include <conio.h>
#include <unistd.h>
#endif

int main()
{
 long time_ms;
#ifdef WIN32
struct _timeb timebuffer;
_ftime( &timebuffer );
time_ms = (long)timebuffer.time * 1000 + (long)timebuffer.millitm;
printf("Windows timing %ld", time_ms);

#else
struct timeval t1;
struct timezone tz;
gettimeofday(&t1, &tz);
time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
    printf("Other timing %ld", time_ms);
 #endif
//    return time_ms;
}`

Error: enter image description here

this is part of complete code, but when i run individually got same error, unable to find solution. i attached error screen shot

GµårÐïåñ
  • 2,846
  • 5
  • 31
  • 35
Ved Yadav
  • 7
  • 2

1 Answers1

0

gettimeofday does not give you the time the CPU has spent on the process, it gives you the real time in the real world. What you want is clock. This will tell you the amount of processing time the program has used. It is a standard ISO C function and should work on any C compiler.

Note that the value it returns is in clock ticks. To get seconds you must divide it by CLOCKS_PER_SEC.

#include <stdio.h>
#include <time.h>

int main(void) {
    clock_t cpu_time;

    for( int i = 1; i <= 10; i++ ) {
        cpu_time = clock();

        printf("CPU time used since program start is: %d clocks or %f seconds\n",
               (int)cpu_time,
               (float)cpu_time / CLOCKS_PER_SEC
        );
    }
}
Schwern
  • 153,029
  • 25
  • 195
  • 336