Last change
on this file since 23 was
1,
checked in by buchmann, 17 years ago
|
Initial import from CVS repository
|
File size:
605 bytes
|
Line | |
---|
1 | #ifndef __CHRONO_H__ |
---|
2 | #define __CHRONO_H__ |
---|
3 | |
---|
4 | #include <sys/time.h> |
---|
5 | #include <sys/resource.h> |
---|
6 | #include <unistd.h> |
---|
7 | |
---|
8 | struct chrono_t { |
---|
9 | unsigned int sec; |
---|
10 | chrono_t () |
---|
11 | { |
---|
12 | sec = 0; |
---|
13 | } |
---|
14 | void start () |
---|
15 | { |
---|
16 | struct rusage usage; |
---|
17 | getrusage(RUSAGE_SELF, &usage); |
---|
18 | sec = usage.ru_utime.tv_sec; |
---|
19 | } |
---|
20 | void cont () |
---|
21 | { |
---|
22 | struct rusage usage; |
---|
23 | getrusage(RUSAGE_SELF, &usage); |
---|
24 | sec = usage.ru_utime.tv_sec - sec; |
---|
25 | } |
---|
26 | void stop () |
---|
27 | { |
---|
28 | cont (); |
---|
29 | } |
---|
30 | operator unsigned int () const |
---|
31 | { return sec; } |
---|
32 | friend std::ostream& operator << (std::ostream& o, const chrono_t &c) |
---|
33 | { |
---|
34 | return o << c.sec << "sec"; |
---|
35 | } |
---|
36 | }; |
---|
37 | |
---|
38 | #endif |
---|
39 | |
---|
Note: See
TracBrowser
for help on using the repository browser.