#include "boost/test/unit_test.hpp"
#include "cetlib/cpu_timer.h"
#include <chrono>
#include <cmath>
#include <iostream>
#include <thread>
#include <sys/resource.h>
Go to the source code of this file.
#define _GLIBCXX_USE_NANOSLEEP 1 |
#define BOOST_TEST_MODULE (cpu_timer_test 2) |
BOOST_AUTO_TEST_CASE |
( |
init |
| ) |
|
Definition at line 66 of file cpu_timer_test.cc.
70 BOOST_TEST(timer().realTime() == 0.0);
71 BOOST_TEST(timer().cpuTime() == 0.0);
BOOST_AUTO_TEST_CASE |
( |
timer1 |
| ) |
|
Definition at line 74 of file cpu_timer_test.cc.
84 BOOST_TEST(timer().realTime() >= 0.050);
85 std::cout <<
"timer1 cpu: " << timer().cpuTime()
86 <<
" real: " << timer().realTime() <<
std::endl;
millisecond milliseconds
Alias for common language habits.
double const small_cputime
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
timer2 |
| ) |
|
Definition at line 90 of file cpu_timer_test.cc.
100 double const cpu = timer().cpuTime();
101 double const real = timer().realTime();
103 BOOST_TEST(real >= 0.050);
millisecond milliseconds
Alias for common language habits.
double const small_cputime
BOOST_AUTO_TEST_CASE |
( |
nullStart |
| ) |
|
Definition at line 107 of file cpu_timer_test.cc.
double const small_realtime
double const small_cputime
BOOST_AUTO_TEST_CASE |
( |
doubleStop |
| ) |
|
Definition at line 120 of file cpu_timer_test.cc.
127 double const dur = 0.150;
130 double real = timer().realTime();
131 double cpu = timer().cpuTime();
134 BOOST_TEST(timer().realTime() == real);
135 BOOST_TEST(timer().cpuTime() == cpu);
double busy_loop(double dur)
BOOST_AUTO_TEST_CASE |
( |
reset |
| ) |
|
Definition at line 138 of file cpu_timer_test.cc.
142 double const dur = 0.150;
145 BOOST_TEST(timer().realTime() > 0.0);
146 BOOST_TEST(timer().cpuTime() > 0.0);
149 BOOST_TEST(timer().realTime() == 0.0);
150 BOOST_TEST(timer().cpuTime() == 0.0);
double busy_loop(double dur)
BOOST_AUTO_TEST_CASE |
( |
checkUsage |
| ) |
|
Definition at line 153 of file cpu_timer_test.cc.
159 double const dur = 0.135;
163 BOOST_TEST(timer().realTime() > 0.0);
164 BOOST_TEST(timer().cpuTime() > 0.0);
double busy_loop(double dur)
double busy_loop |
( |
double |
dur | ) |
|
Definition at line 49 of file cpu_timer_test.cc.
52 rusage start_time, ru;
53 getrusage(RUSAGE_SELF, &start_time);
55 for (
int i = 0; i < 1000; ++i)
57 getrusage(RUSAGE_SELF, &ru);
58 }
while (
time_diff(ru, start_time) < dur);
double time_diff(rusage const &a, rusage const &b)
double time_diff |
( |
rusage const & |
a, |
|
|
rusage const & |
b |
|
) |
| |
|
inline |
Definition at line 38 of file cpu_timer_test.cc.
40 double const sec = (
a.ru_utime.tv_sec -
b.ru_utime.tv_sec) +
41 (
a.ru_stime.tv_sec -
b.ru_stime.tv_sec);
42 double const microsec = (
a.ru_utime.tv_usec -
b.ru_utime.tv_usec) +
43 (
a.ru_stime.tv_usec -
b.ru_stime.tv_usec);
44 return sec + 1
e-6 * microsec;
double const small_cputime = 1.5e-3 |
double const small_realtime = 1.5e-3 |