Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/time.h>
- namespace Time {
- // returns time since this function was first called, in seconds
- inline double Now(){
- static timeval now;
- static timeval start;
- static bool started = false;
- if(!started){
- gettimeofday(&start, 0);
- started = true;
- }
- gettimeofday(&now, 0);
- return (now.tv_sec - start.tv_sec) + (double)(now.tv_usec - start.tv_usec) / (double)1000000;
- }
- inline double Date(){
- static timeval now;
- gettimeofday(&now, 0);
- return now.tv_sec + (double)now.tv_usec / 1000000.0;
- }
- #include <unistd.h>
- inline void Sleep(double ms){
- usleep(ms*1000000.0);
- //double end = Now() + ms;
- //while(Now() < end) sleep(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement