timefunctions in c++

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

void wait ( int seconds )
  clock_t endwait;
  endwait = clock () + seconds * CLK_TCK ;
  while (clock() < endwait) {}

int main ()
  int n;
  printf ("Starting countdown...
  for (n=10; n>0; n--)
    printf ("%d
    wait (1);
  printf ("End!!!
  return 0;

but i have to use float values. another possiblity would be time() but also this function only returns int values. i have to use this code on mac,linux and win. any alternatives? how would you do this?

for linux use the
asm and do rdtsc - read time stamp counter

for windows look for

queryperformancecounter / queryperformancefrequency

since macos is with in some way linux maybe the linux thing will work

the clock function seem not too bad and portable :

the second reply is my current function. are there other possiblities?

(sorry i know it is not opengl specific)


Maybe something along the lines of:

#include <sys/time.h>

struct timeval starttime,endtime;
float elapsedseconds;


// do stuff (rendering and the like)


It’s not super-precise (the actual precision is milliseconds if I’m not mistaken), but it’s elapsed time, not CPU time.

sounds good. but does this work on windows?

yes. thanks