Last change
on this file since 7903 was
7900,
checked in by bensch, 19 years ago
|
gui: implemented the timer right here. now we calc in microseconds
|
File size:
709 bytes
|
Rev | Line | |
---|
[7899] | 1 | /** |
---|
| 2 | * @file timer.cc |
---|
| 3 | * @brief A Timer class, that handles all about time. |
---|
| 4 | * |
---|
| 5 | * code taken from audiere. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "timer.h" |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | #include <time.h> |
---|
| 12 | #include <sys/time.h> |
---|
| 13 | |
---|
[7900] | 14 | /** |
---|
| 15 | * @returns the current time in Second exact to the micro-second |
---|
| 16 | */ |
---|
[7899] | 17 | double Timer::getNow() { |
---|
| 18 | |
---|
| 19 | #if HAVE_CLOCK_GETTIME |
---|
| 20 | // use the POSIX realtime clock to get the current time |
---|
| 21 | struct timespec tp; |
---|
| 22 | int result = clock_gettime(CLOCK_REALTIME, &tp); |
---|
| 23 | if (result == 0) { |
---|
| 24 | return tp.tv_sec * tp.tv_nsec / 1000000000.0; |
---|
| 25 | } |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | // can't use realtime clock! Try to use gettimeofday |
---|
| 29 | struct timeval tv; |
---|
| 30 | gettimeofday(&tv, 0); |
---|
| 31 | return tv.tv_sec + tv.tv_usec / 1000000.0; |
---|
| 32 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.