forked from kevinlin311tw/Caffe-DeepBinaryCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_benchmark.cpp
More file actions
90 lines (77 loc) · 2.43 KB
/
test_benchmark.cpp
File metadata and controls
90 lines (77 loc) · 2.43 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <unistd.h> // for usleep
#include "gtest/gtest.h"
#include "caffe/common.hpp"
#include "caffe/util/benchmark.hpp"
#include "caffe/test/test_caffe_main.hpp"
namespace caffe {
const float kMillisecondsThreshold = 30;
template <typename TypeParam>
class BenchmarkTest : public MultiDeviceTest<TypeParam> {};
TYPED_TEST_CASE(BenchmarkTest, TestDtypesAndDevices);
TYPED_TEST(BenchmarkTest, TestTimerConstructor) {
Timer timer;
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_FALSE(timer.has_run_at_least_once());
}
TYPED_TEST(BenchmarkTest, TestTimerStart) {
Timer timer;
timer.Start();
EXPECT_TRUE(timer.initted());
EXPECT_TRUE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
timer.Start();
EXPECT_TRUE(timer.initted());
EXPECT_TRUE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
timer.Stop();
timer.Start();
EXPECT_TRUE(timer.initted());
EXPECT_TRUE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
}
TYPED_TEST(BenchmarkTest, TestTimerStop) {
Timer timer;
timer.Stop();
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_FALSE(timer.has_run_at_least_once());
timer.Start();
timer.Stop();
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
timer.Stop();
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
}
TYPED_TEST(BenchmarkTest, TestTimerMilliSeconds) {
Timer timer;
EXPECT_EQ(timer.MilliSeconds(), 0);
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_FALSE(timer.has_run_at_least_once());
timer.Start();
usleep(300 * 1000);
EXPECT_GE(timer.MilliSeconds(), 300 - kMillisecondsThreshold);
EXPECT_LE(timer.MilliSeconds(), 300 + kMillisecondsThreshold);
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
}
TYPED_TEST(BenchmarkTest, TestTimerSeconds) {
Timer timer;
EXPECT_EQ(timer.Seconds(), 0);
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_FALSE(timer.has_run_at_least_once());
timer.Start();
usleep(300 * 1000);
EXPECT_GE(timer.Seconds(), 0.3 - kMillisecondsThreshold / 1000.);
EXPECT_LE(timer.Seconds(), 0.3 + kMillisecondsThreshold / 1000.);
EXPECT_TRUE(timer.initted());
EXPECT_FALSE(timer.running());
EXPECT_TRUE(timer.has_run_at_least_once());
}
} // namespace caffe