tstBug.cc 1.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#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;
13
14
    auto func = [](double value)->double
    {
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        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()
33
34
35
                      << " nanoseconds with "
                      << timer1.intervals()
                      << " invervals" << std::endl);
36
    radix_timer_block_2(std::cout << "Second Timer duration: " << timer2.duration()
37
38
39
                        << " nanoseconds with "
                        << timer2.intervals()
                        << " invervals" << std::endl);
40
    radix_timer_block_3(std::cout << "Third Timer duration: " << timer3.duration()
41
42
43
                        << " nanoseconds with "
                        << timer3.intervals()
                        << " invervals" << std::endl);
44
45
46
47
48
49

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

}