Skip to content

Commit fbc033e

Browse files
author
Raghuveer Devulapalli
committed
Add more distance metrics
1 parent 9a92ab0 commit fbc033e

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

benchmarks/bench-objsort.hpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#include <cmath>
2+
3+
static constexpr char x[] = "x";
4+
static constexpr char euclidean[] = "euclidean";
5+
static constexpr char taxicab[] = "taxicab";
6+
static constexpr char chebyshev[] = "chebyshev";
7+
8+
template <const char* val>
29
struct Point3D {
310
double x;
411
double y;
512
double z;
13+
static constexpr std::string_view name {val};
614
Point3D()
715
{
816
x = (double)rand() / RAND_MAX;
@@ -11,21 +19,18 @@ struct Point3D {
1119
}
1220
double distance()
1321
{
14-
return std::sqrt(x * x + y * y + z * z);
15-
}
16-
};
17-
18-
struct Point2D {
19-
double x;
20-
double y;
21-
Point2D()
22-
{
23-
x = (double)rand() / RAND_MAX;
24-
y = (double)rand() / RAND_MAX;
25-
}
26-
double distance()
27-
{
28-
return std::sqrt(x * x + y * y);
22+
if constexpr (name == "x") {
23+
return x;
24+
}
25+
else if constexpr (name == "euclidean") {
26+
return std::sqrt(x * x + y * y + z * z);
27+
}
28+
else if constexpr (name == "taxicab") {
29+
return abs(x) + abs(y) + abs(z);
30+
}
31+
else if constexpr (name == "chebyshev") {
32+
return std::max(std::max(x, y), z);
33+
}
2934
}
3035
};
3136

@@ -93,7 +98,11 @@ static void simdobjsort(benchmark::State &state)
9398
->Arg(10e5) \
9499
->Arg(10e6);
95100

96-
BENCHMARK_OBJSORT(simdobjsort, Point2D)
97-
BENCHMARK_OBJSORT(scalarobjsort, Point2D)
98-
BENCHMARK_OBJSORT(simdobjsort, Point3D)
99-
BENCHMARK_OBJSORT(scalarobjsort, Point3D)
101+
BENCHMARK_OBJSORT(simdobjsort, Point3D<x>)
102+
BENCHMARK_OBJSORT(scalarobjsort, Point3D<x>)
103+
BENCHMARK_OBJSORT(simdobjsort, Point3D<taxicab>)
104+
BENCHMARK_OBJSORT(scalarobjsort, Point3D<taxicab>)
105+
BENCHMARK_OBJSORT(simdobjsort, Point3D<euclidean>)
106+
BENCHMARK_OBJSORT(scalarobjsort, Point3D<euclidean>)
107+
BENCHMARK_OBJSORT(simdobjsort, Point3D<chebyshev>)
108+
BENCHMARK_OBJSORT(scalarobjsort, Point3D<chebyshev>)

0 commit comments

Comments
 (0)