ArmNN
 21.02
InstrumentTests.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "WallClockTimer.hpp"
#include <chrono>
#include <thread>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (WallClockTimerInMicroseconds)
 
 BOOST_AUTO_TEST_CASE (WallClockTimerInNanoseconds)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( WallClockTimerInMicroseconds  )

Definition at line 16 of file InstrumentTests.cpp.

References WallClockTimer::GetMeasurements(), WallClockTimer::GetName(), WallClockTimer::Start(), WallClockTimer::Stop(), and WallClockTimer::WALL_CLOCK_TIME.

17 {
18  WallClockTimer wallClockTimer;
19 
20  BOOST_CHECK_EQUAL(wallClockTimer.GetName(), "WallClockTimer");
21 
22  // start the timer
23  wallClockTimer.Start();
24 
25  // wait for 10 microseconds
26  std::this_thread::sleep_for(std::chrono::microseconds(10));
27 
28  // stop the timer
29  wallClockTimer.Stop();
30 
31  BOOST_CHECK_EQUAL(wallClockTimer.GetMeasurements().front().m_Name, WallClockTimer::WALL_CLOCK_TIME);
32 
33  // check that WallClockTimer measurement should be >= 10 microseconds
34  BOOST_CHECK_GE(wallClockTimer.GetMeasurements().front().m_Value, std::chrono::microseconds(10).count());
35 }
void Start() override
const char * GetName() const override
void Stop() override
std::vector< Measurement > GetMeasurements() const override

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( WallClockTimerInNanoseconds  )

Definition at line 37 of file InstrumentTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), WallClockTimer::GetMeasurements(), WallClockTimer::GetName(), WallClockTimer::Start(), WallClockTimer::Stop(), and WallClockTimer::WALL_CLOCK_TIME.

38 {
39  WallClockTimer wallClockTimer;
40 
41  BOOST_CHECK_EQUAL(wallClockTimer.GetName(), "WallClockTimer");
42 
43  // start the timer
44  wallClockTimer.Start();
45 
46  // wait for 500 nanoseconds - 0.5 microseconds
47  std::this_thread::sleep_for(std::chrono::nanoseconds(500));
48 
49  // stop the timer
50  wallClockTimer.Stop();
51 
52  BOOST_CHECK_EQUAL(wallClockTimer.GetMeasurements().front().m_Name, WallClockTimer::WALL_CLOCK_TIME);
53 
54  // delta is 0.5 microseconds
55  const auto delta =
56  std::chrono::duration_cast<std::chrono::duration<double, std::micro>>(std::chrono::nanoseconds(500));
57 
58  // check that WallClockTimer measurement should be >= 0.5 microseconds
59  BOOST_CHECK_GE(wallClockTimer.GetMeasurements().front().m_Value, delta.count());
60 }
void Start() override
const char * GetName() const override
void Stop() override
std::vector< Measurement > GetMeasurements() const override