Permalink
Browse files

Relaxed interval checks in timer tests

  • Loading branch information...
petya2164 committed Apr 7, 2017
1 parent 5af5def commit e367434e3a51bbd8f6030e11a4628e591a657e53
Showing with 25 additions and 43 deletions.
  1. +8 −7 test/src/test_boost_asio_timer.cpp
  2. +17 −36 test/src/test_time.cpp
@@ -18,8 +18,9 @@ struct boost_asio_timer_benchmark : public gauge::time_benchmark
{
// Get the time spent sleeping
double time = gauge::time_benchmark::measurement();
// This should be higher than the requested time
EXPECT_GT(time, m_delay.count());
// This should be higher than 99% of the requested time
// The timer might expire a little earlier on Windows
EXPECT_GE(time, m_delay.count() * 0.99);
return time;
}
@@ -56,24 +57,24 @@ struct boost_asio_timer_benchmark : public gauge::time_benchmark
boost::chrono::microseconds m_delay;
};
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 100msec, 1)
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, AsioTimer, 100msec, 1)
{
run_benchmark(boost::chrono::milliseconds(100));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 10msec, 1)
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, AsioTimer, 10msec, 1)
{
run_benchmark(boost::chrono::milliseconds(10));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 1msec, 1)
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, AsioTimer, 1msec, 1)
{
run_benchmark(boost::chrono::milliseconds(1));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 1usec, 1)
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, AsioTimer, 10usec, 1)
{
run_benchmark(boost::chrono::microseconds(1));
run_benchmark(boost::chrono::microseconds(10));
}
TEST(Gauge, boost_asio_timer)
View
@@ -18,48 +18,49 @@ struct sleep_benchmark : public gauge::time_benchmark
{
// Get the time spent sleeping
double time = gauge::time_benchmark::measurement();
// This should be higher than the requested time
EXPECT_GT(time, m_last_delay);
// This should be higher than 99% of the requested time
// The sleep period might end a little earlier on Windows
EXPECT_GE(time, m_delay.count() * 0.99);
return time;
}
void run_benchmark(uint32_t delay)
void run_benchmark(bc::microseconds delay)
{
m_last_delay = delay;
m_delay = delay;
RUN
{
boost::this_thread::sleep_for(bc::microseconds(delay));
boost::this_thread::sleep_for(delay);
}
}
protected:
uint32_t m_last_delay;
bc::microseconds m_delay;
};
BENCHMARK_F_INLINE(sleep_benchmark, Gauge, sleep_10usecs, 1)
BENCHMARK_F_INLINE(sleep_benchmark, Sleep, 10usec, 1)
{
run_benchmark(10);
run_benchmark(bc::microseconds(10));
}
BENCHMARK_F_INLINE(sleep_benchmark, Gauge, sleep_100usecs, 1)
BENCHMARK_F_INLINE(sleep_benchmark, Sleep, 100usec, 1)
{
run_benchmark(100);
run_benchmark(bc::microseconds(100));
}
BENCHMARK_F_INLINE(sleep_benchmark, Gauge, sleep_1000usecs, 1)
BENCHMARK_F_INLINE(sleep_benchmark, Sleep, 1msec, 1)
{
run_benchmark(1000);
run_benchmark(bc::milliseconds(1));
}
BENCHMARK_F_INLINE(sleep_benchmark, Gauge, sleep_10000usecs, 1)
BENCHMARK_F_INLINE(sleep_benchmark, Sleep, 10msec, 1)
{
run_benchmark(10000);
run_benchmark(bc::milliseconds(10));
}
BENCHMARK_F_INLINE(sleep_benchmark, Gauge, sleep_100000usecs, 1)
BENCHMARK_F_INLINE(sleep_benchmark, Sleep, 100msec, 1)
{
run_benchmark(100000);
run_benchmark(bc::milliseconds(100));
}
TEST(Gauge, sleep_intervals)
@@ -68,25 +69,5 @@ TEST(Gauge, sleep_intervals)
int argc = 1;
const char* argv[] = { "program" };
gauge::runner::add_default_printers();
gauge::runner::run_benchmarks(argc, argv);
}
// TEST(Gauge, reference_sleep_intervals)
// {
// uint32_t loop = 100000;
// auto start = bc::high_resolution_clock::now();
// for(uint32_t i = 0; i < loop; ++i)
// boost::this_thread::sleep_for(bc::microseconds(10));
// auto stop = bc::high_resolution_clock::now();
// auto duration = static_cast<double>(
// bc::duration_cast<bc::microseconds>(stop - start).count());
// std::cout << "Duration " << duration << std::endl;
// std::cout << "Duration per loop" << duration/loop << std::endl;
// }

0 comments on commit e367434

Please sign in to comment.