get_seconds.h 629 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef IGL_GET_SECONDS_H
  2. #define IGL_GET_SECONDS_H
  3. namespace igl
  4. {
  5. // Return the current time in seconds since program start
  6. inline double get_seconds();
  7. }
  8. // Implementation
  9. #if _WIN32
  10. # include <ctime>
  11. inline double igl::get_seconds()
  12. {
  13. // This does not work on mac os x with glut in the main loop
  14. return double(clock())/CLOCKS_PER_SEC;
  15. }
  16. #else
  17. # include <sys/time.h>
  18. inline double igl::get_seconds()
  19. {
  20. timeval time;
  21. gettimeofday(&time, NULL);
  22. return time.tv_sec + time.tv_usec / 1e6;
  23. // This does not work on mac os x with glut in the main loop
  24. //return double(clock())/CLOCKS_PER_SEC;
  25. }
  26. #endif
  27. #endif