Skip to content

Commit c1a155b

Browse files
[llvm-exegesis] Refactor BenchmarkMeasure instantiation in tests
This patch refactors the instantiation of BenchmarkMeasure within all the unit tests to use BenchmarkMeasure::Create rather than through direct struct instantialization. This allows us to change what values are stored in BenchmarkMeasure without getting compiler warnings on every instantiation in the unit tests, and is also just a cleanup in general as the Create function didn't seem to exist at the time the unit tests were originally written.
1 parent 2e1e27c commit c1a155b

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@ TEST(ClusteringTest, Clusters3D) {
3131
std::vector<Benchmark> Points(6);
3232

3333
// Cluster around (x=0, y=1, z=2): points {0, 3}.
34-
Points[0].Measurements = {
35-
{"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
36-
Points[3].Measurements = {
37-
{"x", -0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
34+
Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
35+
BenchmarkMeasure::Create("y", 1.02, {}),
36+
BenchmarkMeasure::Create("z", 1.98, {})};
37+
Points[3].Measurements = {BenchmarkMeasure::Create("x", -0.01, {}),
38+
BenchmarkMeasure::Create("y", 1.02, {}),
39+
BenchmarkMeasure::Create("z", 1.98, {})};
3840
// Cluster around (x=1, y=1, z=2): points {1, 4}.
39-
Points[1].Measurements = {
40-
{"x", 1.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
41-
Points[4].Measurements = {
42-
{"x", 0.99, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
41+
Points[1].Measurements = {BenchmarkMeasure::Create("x", 1.01, {}),
42+
BenchmarkMeasure::Create("y", 1.02, {}),
43+
BenchmarkMeasure::Create("z", 1.98, {})};
44+
Points[4].Measurements = {BenchmarkMeasure::Create("x", 0.99, {}),
45+
BenchmarkMeasure::Create("y", 1.02, {}),
46+
BenchmarkMeasure::Create("z", 1.98, {})};
4347
// Cluster around (x=0, y=0, z=0): points {5}, marked as noise.
44-
Points[5].Measurements = {
45-
{"x", 0.0, 0.0, {}}, {"y", 0.01, 0.0, {}}, {"z", -0.02, 0.0, {}}};
48+
Points[5].Measurements = {BenchmarkMeasure::Create("x", 0.0, {}),
49+
BenchmarkMeasure::Create("y", 0.01, {}),
50+
BenchmarkMeasure::Create("z", -0.02, {})};
4651
// Error cluster: points {2}
4752
Points[2].Error = "oops";
4853

@@ -70,9 +75,11 @@ TEST(ClusteringTest, Clusters3D) {
7075

7176
TEST(ClusteringTest, Clusters3D_InvalidSize) {
7277
std::vector<Benchmark> Points(6);
73-
Points[0].Measurements = {
74-
{"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
75-
Points[1].Measurements = {{"y", 1.02, 0.0, {}}, {"z", 1.98, 0.0, {}}};
78+
Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
79+
BenchmarkMeasure::Create("y", 1.02, {}),
80+
BenchmarkMeasure::Create("z", 1.98, {})};
81+
Points[1].Measurements = {BenchmarkMeasure::Create("y", 1.02, {}),
82+
BenchmarkMeasure::Create("z", 1.98, {})};
7683
auto Error =
7784
BenchmarkClustering::create(
7885
Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25)
@@ -83,8 +90,10 @@ TEST(ClusteringTest, Clusters3D_InvalidSize) {
8390

8491
TEST(ClusteringTest, Clusters3D_InvalidOrder) {
8592
std::vector<Benchmark> Points(6);
86-
Points[0].Measurements = {{"x", 0.01, 0.0, {}}, {"y", 1.02, 0.0, {}}};
87-
Points[1].Measurements = {{"y", 1.02, 0.0, {}}, {"x", 1.98, 0.0, {}}};
93+
Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.01, {}),
94+
BenchmarkMeasure::Create("y", 1.02, {})};
95+
Points[1].Measurements = {BenchmarkMeasure::Create("y", 1.02, {}),
96+
BenchmarkMeasure::Create("x", 1.98, {})};
8897
auto Error =
8998
BenchmarkClustering::create(
9099
Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25)
@@ -110,9 +119,9 @@ TEST(ClusteringTest, Ordering) {
110119
TEST(ClusteringTest, Ordering1) {
111120
std::vector<Benchmark> Points(3);
112121

113-
Points[0].Measurements = {{"x", 0.0, 0.0, {}}};
114-
Points[1].Measurements = {{"x", 1.0, 0.0, {}}};
115-
Points[2].Measurements = {{"x", 2.0, 0.0, {}}};
122+
Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.0, {})};
123+
Points[1].Measurements = {BenchmarkMeasure::Create("x", 1.0, {})};
124+
Points[2].Measurements = {BenchmarkMeasure::Create("x", 2.0, {})};
116125

117126
auto Clustering = BenchmarkClustering::create(
118127
Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1);
@@ -124,9 +133,9 @@ TEST(ClusteringTest, Ordering1) {
124133
TEST(ClusteringTest, Ordering2) {
125134
std::vector<Benchmark> Points(3);
126135

127-
Points[0].Measurements = {{"x", 0.0, 0.0, {}}};
128-
Points[1].Measurements = {{"x", 2.0, 0.0, {}}};
129-
Points[2].Measurements = {{"x", 1.0, 0.0, {}}};
136+
Points[0].Measurements = {BenchmarkMeasure::Create("x", 0.0, {})};
137+
Points[1].Measurements = {BenchmarkMeasure::Create("x", 2.0, {})};
138+
Points[2].Measurements = {BenchmarkMeasure::Create("x", 1.0, {})};
130139

131140
auto Clustering = BenchmarkClustering::create(
132141
Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1);

llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) {
6565
ToDisk.CpuName = "cpu_name";
6666
ToDisk.LLVMTriple = "llvm_triple";
6767
ToDisk.NumRepetitions = 1;
68-
ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, 1, {}});
69-
ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, 2, {}});
68+
ToDisk.Measurements.push_back(BenchmarkMeasure::Create("a", 1, {}));
69+
ToDisk.Measurements.push_back(BenchmarkMeasure::Create("b", 2, {}));
7070
ToDisk.Error = "error";
7171
ToDisk.Info = "info";
7272

@@ -124,10 +124,10 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) {
124124

125125
TEST_F(MipsBenchmarkResultTest, PerInstructionStats) {
126126
PerInstructionStats Stats;
127-
Stats.push(BenchmarkMeasure{"a", 0.5, 0.0, {}});
128-
Stats.push(BenchmarkMeasure{"a", 1.5, 0.0, {}});
129-
Stats.push(BenchmarkMeasure{"a", -1.0, 0.0, {}});
130-
Stats.push(BenchmarkMeasure{"a", 0.0, 0.0, {}});
127+
Stats.push(BenchmarkMeasure::Create("a", 0.5, {}));
128+
Stats.push(BenchmarkMeasure::Create("a", 1.5, {}));
129+
Stats.push(BenchmarkMeasure::Create("a", -1.0, {}));
130+
Stats.push(BenchmarkMeasure::Create("a", 0.0, {}));
131131
EXPECT_EQ(Stats.min(), -1.0);
132132
EXPECT_EQ(Stats.max(), 1.5);
133133
EXPECT_EQ(Stats.avg(), 0.25); // (0.5+1.5-1.0+0.0) / 4

llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
8484
ToDisk.CpuName = "cpu_name";
8585
ToDisk.LLVMTriple = "llvm_triple";
8686
ToDisk.NumRepetitions = 1;
87-
ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, 1, {}});
88-
ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, 2, {}});
87+
ToDisk.Measurements.push_back(BenchmarkMeasure::Create("a", 1, {}));
88+
ToDisk.Measurements.push_back(BenchmarkMeasure::Create("b", 2, {}));
8989
ToDisk.Error = "error";
9090
ToDisk.Info = "info";
9191

@@ -162,10 +162,10 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
162162

163163
TEST(BenchmarkResultTest, PerInstructionStats) {
164164
PerInstructionStats Stats;
165-
Stats.push(BenchmarkMeasure{"a", 0.5, 0.0, {}});
166-
Stats.push(BenchmarkMeasure{"a", 1.5, 0.0, {}});
167-
Stats.push(BenchmarkMeasure{"a", -1.0, 0.0, {}});
168-
Stats.push(BenchmarkMeasure{"a", 0.0, 0.0, {}});
165+
Stats.push(BenchmarkMeasure::Create("a", 0.5, {}));
166+
Stats.push(BenchmarkMeasure::Create("a", 1.5, {}));
167+
Stats.push(BenchmarkMeasure::Create("a", -1.0, {}));
168+
Stats.push(BenchmarkMeasure::Create("a", 0.0, {}));
169169
EXPECT_EQ(Stats.min(), -1.0);
170170
EXPECT_EQ(Stats.max(), 1.5);
171171
EXPECT_EQ(Stats.avg(), 0.25); // (0.5+1.5-1.0+0.0) / 4

0 commit comments

Comments
 (0)