A
lgorithmique
N
umérique
D
istribuée
Private GIT Repository
projects
/
loba.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
run-all: check existence of platform files.
[loba.git]
/
timer.h
diff --git
a/timer.h
b/timer.h
index b9a25099630063bd41d851cabaed8764fb012222..52502a1f10eca8c23935491fc693acd9b7c5ecaf 100644
(file)
--- a/
timer.h
+++ b/
timer.h
@@
-1,51
+1,31
@@
#ifndef TIMER_H
#define TIMER_H
#ifndef TIMER_H
#define TIMER_H
-#include <sys/time.h>
-#include <sys/resource.h>
-
-#ifdef _BSD_SOURCE
-# define HAVE_TIMERADD
-# define HAVE_TIMERSUB
-# define HAVE_TIMERCLEAR
-#else
-# warning _BSD_SOURCE not defined
-# undef HAVE_TIMERADD
-# undef HAVE_TIMERSUB
-# undef HAVE_TIMERCLEAR
-#endif
+#include <ctime>
inline
inline
-struct time
val operator+(const struct timeval& a, const struct timeval
& b)
+struct time
spec operator+(const struct timespec& a, const struct timespec
& b)
{
{
- struct timeval result;
-#ifdef HAVE_TIMERADD
- timeradd(&a, &b, &result);
-#else
+ struct timespec result;
result.tv_sec = a.tv_sec + b.tv_sec;
result.tv_sec = a.tv_sec + b.tv_sec;
- result.tv_
usec = a.tv_usec + b.tv_u
sec;
- if (result.tv_
usec >= 1000000
) {
+ result.tv_
nsec = a.tv_nsec + b.tv_n
sec;
+ if (result.tv_
nsec >= 1000000000L
) {
++result.tv_sec;
++result.tv_sec;
- result.tv_
usec -= 1000000
;
+ result.tv_
nsec -= 1000000000L
;
}
}
-#endif
return result;
}
inline
return result;
}
inline
-struct time
val operator-(const struct timeval& a, const struct timeval
& b)
+struct time
spec operator-(const struct timespec& a, const struct timespec
& b)
{
{
- struct timeval result;
-#ifdef HAVE_TIMERSUB
- timersub(&a, &b, &result);
-#else
+ struct timespec result;
result.tv_sec = a.tv_sec - b.tv_sec;
result.tv_sec = a.tv_sec - b.tv_sec;
- result.tv_
usec = a.tv_usec - b.tv_u
sec;
- if (result.tv_
u
sec < 0) {
+ result.tv_
nsec = a.tv_nsec - b.tv_n
sec;
+ if (result.tv_
n
sec < 0) {
--result.tv_sec;
--result.tv_sec;
- result.tv_
usec += 1000000
;
+ result.tv_
nsec += 1000000000L
;
}
}
-#endif
return result;
}
return result;
}
@@
-60,19
+40,19
@@
public:
void start();
void stop();
void start();
void stop();
- struct time
val
tv_duration() const;
+ struct time
spec
tv_duration() const;
double duration() const;
private:
clock_type clk;
double duration() const;
private:
clock_type clk;
- struct time
val
before;
- struct time
val
after;
- struct time
val
difference;
+ struct time
spec
before;
+ struct time
spec
after;
+ struct time
spec
difference;
- void get_time(struct time
val
& tv);
+ void get_time(struct time
spec
& tv);
- static void tv_clear(struct time
val
& a);
- static double timertod(const struct time
val
& a);
+ static void tv_clear(struct time
spec
& a);
+ static double timertod(const struct time
spec
& a);
};
inline
};
inline
@@
-108,7
+88,7
@@
void timestamp::stop()
}
inline
}
inline
-struct time
val
timestamp::tv_duration() const
+struct time
spec
timestamp::tv_duration() const
{
return difference;
}
{
return difference;
}
@@
-120,35
+100,34
@@
double timestamp::duration() const
}
inline
}
inline
-void timestamp::get_time(struct time
val
& tv)
+void timestamp::get_time(struct time
spec
& tv)
{
switch (clk) {
case cpu_time: {
{
switch (clk) {
case cpu_time: {
- struct rusage usage;
- getrusage(RUSAGE_SELF, &usage);
- tv = usage.ru_utime + usage.ru_stime;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tv);
break;
}
case wallclock_time:
break;
}
case wallclock_time:
- gettimeofday(&tv, NULL);
+#ifdef CLOCK_MONOTONIC_RAW
+ clock_gettime(CLOCK_MONOTONIC_RAW, &tv);
+#else
+ clock_gettime(CLOCK_MONOTONIC, &tv);
+#endif
break;
}
}
inline
break;
}
}
inline
-void timestamp::tv_clear(struct time
val
& a)
+void timestamp::tv_clear(struct time
spec
& a)
{
{
-#ifdef HAVE_TIMERCLEAR
- timerclear(&a);
-#else
- tv.sec = tv.usec = 0;
-#endif
+ a.tv_sec = 0;
+ a.tv_nsec = 0;
}
inline
}
inline
-double timestamp::timertod(const struct time
val
& a)
+double timestamp::timertod(const struct time
spec
& a)
{
{
- return a.tv_sec + a.tv_
usec / 1e6
;
+ return a.tv_sec + a.tv_
nsec / 1e9
;
}
#endif // !TIMER_H
}
#endif // !TIMER_H