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
-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux