aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/InstrumentTests.cpp
blob: 447a4c9d58bac4cb03059782a0951fce04370a81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include <doctest/doctest.h>

#include "WallClockTimer.hpp"

#include <chrono>
#include <thread>

using namespace armnn;

TEST_SUITE("Instruments")
{
TEST_CASE("WallClockTimerInMicroseconds")
{
    WallClockTimer wallClockTimer;

    CHECK((std::string(wallClockTimer.GetName()) == std::string("WallClockTimer")));

    // start the timer
    wallClockTimer.Start();

    // wait for 10 microseconds
    std::this_thread::sleep_for(std::chrono::microseconds(10));

   // stop the timer
    wallClockTimer.Stop();

    CHECK((wallClockTimer.GetMeasurements().front().m_Name == WallClockTimer::WALL_CLOCK_TIME));

    // check that WallClockTimer measurement should be >= 10 microseconds
    CHECK_GE(wallClockTimer.GetMeasurements().front().m_Value, std::chrono::microseconds(10).count());
}

TEST_CASE("WallClockTimerInNanoseconds")
{
    WallClockTimer wallClockTimer;

    CHECK((std::string(wallClockTimer.GetName()) == std::string("WallClockTimer")));

    // start the timer
    wallClockTimer.Start();

    // wait for 500 nanoseconds - 0.5 microseconds
    std::this_thread::sleep_for(std::chrono::nanoseconds(500));

    // stop the timer
    wallClockTimer.Stop();

    CHECK((wallClockTimer.GetMeasurements().front().m_Name == WallClockTimer::WALL_CLOCK_TIME));

    // delta is 0.5 microseconds
    const auto delta =
        std::chrono::duration_cast<std::chrono::duration<double, std::micro>>(std::chrono::nanoseconds(500));

    // check that WallClockTimer measurement should be >= 0.5 microseconds
    CHECK_GE(wallClockTimer.GetMeasurements().front().m_Value, delta.count());
}

}