tstBug.cc 1.41 KB
Newer Older
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
#include "gtest/gtest.h"

// force RADIX_TIMING on
#define RADIX_TIMING 3
#include "radixbug/bug.hh"

TEST(radixbug, Timer)
{
    radix_timer(timer1);
    radix_timer_2(timer2);
    radix_timer_3(timer3);
    double value = 0;
    auto func = [](double value)->double{
        return value * value;
    };
    //
    // demostrate timing metrics
    radix_timer_start(timer1);
    for(size_t i = 0; i < 100; ++i)
    {
        radix_timer_start_2(timer2);
        for(size_t j = 0; j < 10000; ++j)
        {
            radix_timer_start_3(timer3);
            value = value + func(value);
            radix_timer_stop_3(timer3);
        }
        radix_timer_stop_2(timer2);
    }
    radix_timer_stop(timer1);
    radix_timer_block(std::cout << "First Timer duration: " << timer1.duration()
              << " nanoseconds with "
              << timer1.intervals()
              << " invervals" << std::endl);
    radix_timer_block_2(std::cout << "Second Timer duration: " << timer2.duration()
              << " nanoseconds with "
              << timer2.intervals()
              << " invervals" << std::endl);
    radix_timer_block_3(std::cout << "Third Timer duration: " << timer3.duration()
              << " nanoseconds with "
              << timer3.intervals()
              << " invervals" << std::endl);

    EXPECT_EQ(timer1.intervals(), 1);
    EXPECT_EQ(timer2.intervals(), 100);
    EXPECT_EQ(timer3.intervals(), (100*10000));

}