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
",n);
    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 :
http://www.cplusplus.com/ref/ctime/clock.html

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

(sorry i know it is not opengl specific)

thanks

Maybe something along the lines of:

#include <sys/time.h>

struct timeval starttime,endtime;
float elapsedseconds;

gettimeofday(&starttime,NULL);

// do stuff (rendering and the like)

gettimeofday(&endtime,NULL);
  elapsedseconds=(float)((endtime.tv_sec-starttime.tv_sec)%86400)+(float)(endtime.tv_usec-starttime.tv_usec)/1000000.0;

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