Advertisement
WeltEnSTurm

Untitled

Nov 2nd, 2011
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1.  
  2.     #include <sys/time.h>
  3.     namespace Time {
  4.         // returns time since this function was first called, in seconds
  5.         inline double Now(){
  6.             static timeval now;
  7.             static timeval start;
  8.  
  9.             static bool started = false;
  10.             if(!started){
  11.                 gettimeofday(&start, 0);
  12.                 started = true;
  13.             }
  14.  
  15.             gettimeofday(&now, 0);
  16.             return (now.tv_sec - start.tv_sec) + (double)(now.tv_usec - start.tv_usec) / (double)1000000;
  17.         }
  18.  
  19.         inline double Date(){
  20.             static timeval now;
  21.             gettimeofday(&now, 0);
  22.             return now.tv_sec + (double)now.tv_usec / 1000000.0;
  23.         }
  24.  
  25.         #include <unistd.h>
  26.  
  27.         inline void Sleep(double ms){
  28.             usleep(ms*1000000.0);
  29.             //double end = Now() + ms;
  30.             //while(Now() < end) sleep(0);
  31.         }
  32.     }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement