Last change
on this file since 10681 was
9658,
checked in by bensch, 18 years ago
|
new smooth-allocator class, this is also a test, to see, if my template experience is good enough for the C++ generic Template Programming Lecture
|
File size:
1003 bytes
|
Line | |
---|
1 | /** |
---|
2 | * @file timer.cc |
---|
3 | * @brief A Timer class, that handles all about time. |
---|
4 | * |
---|
5 | * code borrowed from audiere. http://www.audiere.org |
---|
6 | */ |
---|
7 | |
---|
8 | #include "timer.h" |
---|
9 | |
---|
10 | |
---|
11 | #include <time.h> |
---|
12 | #include <sys/time.h> |
---|
13 | |
---|
14 | #ifdef __WIN32__ |
---|
15 | #include <windows.h> |
---|
16 | int gettimeofday |
---|
17 | (struct timeval* tp, void* tzp) { |
---|
18 | DWORD t; |
---|
19 | t = timeGetTime(); |
---|
20 | tp->tv_sec = t / 1000; |
---|
21 | tp->tv_usec = 1000 * (t % 1000 ); |
---|
22 | /* 0 indicates success. */ |
---|
23 | return 0; |
---|
24 | } |
---|
25 | #endif |
---|
26 | |
---|
27 | /** |
---|
28 | * @returns the current time in Second exact to the micro-second |
---|
29 | */ |
---|
30 | double Timer::getNow() { |
---|
31 | |
---|
32 | #if HAVE_CLOCK_GETTIME |
---|
33 | |
---|
34 | // use the POSIX realtime clock to get the current time |
---|
35 | struct timespec tp; |
---|
36 | int result = clock_gettime(CLOCK_REALTIME, &tp); |
---|
37 | if (result == 0) { |
---|
38 | return tp.tv_sec * tp.tv_nsec / 1000000000.0; |
---|
39 | } |
---|
40 | #endif |
---|
41 | |
---|
42 | // can't use realtime clock! Try to use gettimeofday |
---|
43 | struct timeval tv; |
---|
44 | gettimeofday(&tv, 0); |
---|
45 | return tv.tv_sec + tv.tv_usec / 1000000.0; |
---|
46 | } |
---|
47 | |
---|
Note: See
TracBrowser
for help on using the repository browser.