Permalink
Browse files

Merge pull request #35 from steinwurf/test-boost-asio-timer

added boost asio timer test
  • Loading branch information...
petya2164 committed Apr 7, 2017
2 parents 97dffb5 + dd62024 commit 5af5def768112a339a92d9fbe05cc16dcb70ce58
Showing with 86 additions and 0 deletions.
  1. +86 −0 test/src/test_boost_asio_timer.cpp
@@ -0,0 +1,86 @@
// Copyright (c) 2016 Steinwurf ApS
// All Rights Reserved
//
// Distributed under the "BSD License". See the accompanying LICENSE.rst file.
#include <gauge/gauge.hpp>
#include <gtest/gtest.h>
#include <boost/chrono.hpp>
#include <boost/asio.hpp>
struct boost_asio_timer_benchmark : public gauge::time_benchmark
{
using clock_type = boost::chrono::high_resolution_clock;
double measurement()
{
// 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());
return time;
}
void run_benchmark(boost::chrono::microseconds delay)
{
m_delay = delay;
boost::asio::basic_waitable_timer<clock_type> timer(m_io);
RUN
{
timer.expires_from_now(m_delay);
timer.async_wait(
std::bind(&boost_asio_timer_benchmark::timeout_handler,
this,
std::placeholders::_1));
m_io.run();
// reset the io service in order for it to work on the next run.
m_io.reset();
}
}
void timeout_handler(const boost::system::error_code& ec)
{
(void)ec;
}
protected:
boost::asio::io_service m_io;
boost::chrono::microseconds m_delay;
};
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 100msec, 1)
{
run_benchmark(boost::chrono::milliseconds(100));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 10msec, 1)
{
run_benchmark(boost::chrono::milliseconds(10));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 1msec, 1)
{
run_benchmark(boost::chrono::milliseconds(1));
}
BENCHMARK_F_INLINE(boost_asio_timer_benchmark, Gauge, 1usec, 1)
{
run_benchmark(boost::chrono::microseconds(1));
}
TEST(Gauge, boost_asio_timer)
{
// Dummy arguments for gauge::runner
int argc = 1;
const char* argv[] = { "program" };
gauge::runner::run_benchmarks(argc, argv);
}

0 comments on commit 5af5def

Please sign in to comment.