clock() - Does it work?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have an animation program that uses the clock() function
for synchronization. It works fine with MinGW 3.2, but not with gcc 4.1.2 (FC6).

In the later case, clock() always return 0. I saw some people pointing at the same problem
in the past, but I thought it would have been fixed by now.

I managed to implement "getus", which seems to do what I need. Is this the right course?

Thanks.
__________________________________________________________________

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

#define getus(tv) (tv.tv_sec*CLOCKS_PER_SEC + tv.tv_usec)
int main() {
  clock_t ca,cb;
  time_t wa,wb;
  struct timeval tva, tvb;
  double c,w;
  double d;
  char s[10];
  ca = clock();
  wa = time(0);
  gettimeofday(&tva, NULL);
  printf("hit enter when ready ");
  fflush (stdout);
  gets(s);
  cb = clock();
  wb = time(0);
  gettimeofday(&tvb, NULL);
  c = (double) (cb-ca);
  w = (double) difftime(wb,wa);
  c /= (double) CLOCKS_PER_SEC;
  d = (getus(tvb) - getus(tva))/(double) CLOCKS_PER_SEC;
  printf ("cps=%d ", CLOCKS_PER_SEC);
  printf("wall=%g, cpu=%g, us=%g\n",w,c,d);
}

--
Paulo Roma Cavalcanti
LCG - UFRJ

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux