2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
9 #include <sys/resource.h>
12 #include "timedelta.h"
13 #include "timestamp.h"
21 Returns the current timestamp.
28 return TimeStamp(tv.tv_sec*1000000LL+tv.tv_usec);
30 static int64_t epoch=0;
43 SystemTimeToFileTime(&st, &ft);
44 epoch=(ft.dwLowDateTime+(int64_t)ft.dwHighDateTime<<32)/10;
48 GetSystemTimeAsFileTime(&ft);
49 return TimeStamp((ft.dwLowDateTime+(int64_t)ft.dwHighDateTime<<32)/10-epoch);
54 Returns the CPU time used by the program so far.
56 TimeDelta get_cpu_time()
60 getrusage(RUSAGE_SELF, &ru);
61 return (ru.ru_utime.tv_sec+ru.ru_stime.tv_sec)*sec + (ru.ru_utime.tv_usec+ru.ru_stime.tv_usec)*usec;
63 //XXX Figure out the function to use on Win32
69 Sleeps for the given time.
71 int sleep(const TimeDelta &d)
76 return nanosleep(&ts, 0);