Skip to content

Commit 10d344c

Browse files
author
Raghuveer Devulapalli
committed
Use type template in objsort
1 parent a69164f commit 10d344c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

benchmarks/bench-objsort.hpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ static constexpr char euclidean[] = "euclidean";
55
static constexpr char taxicab[] = "taxicab";
66
static constexpr char chebyshev[] = "chebyshev";
77

8-
template <const char* val>
8+
template <typename T, const char* val>
99
struct Point3D {
10-
double x;
11-
double y;
12-
double z;
10+
T x;
11+
T y;
12+
T z;
1313
static constexpr std::string_view name {val};
1414
Point3D()
1515
{
16-
x = (double)rand() / RAND_MAX;
17-
y = (double)rand() / RAND_MAX;
18-
z = (double)rand() / RAND_MAX;
16+
x = (T)rand() / RAND_MAX;
17+
y = (T)rand() / RAND_MAX;
18+
z = (T)rand() / RAND_MAX;
1919
}
20-
double distance()
20+
T distance()
2121
{
2222
if constexpr (name == "x") {
2323
return x;
@@ -77,7 +77,7 @@ static void simdobjsort(benchmark::State &state)
7777
std::vector<T> arr_bkp = arr;
7878
// benchmark
7979
for (auto _ : state) {
80-
x86simdsort::object_qsort(arr.data(), arr.size(), [](T p) -> double {
80+
x86simdsort::object_qsort(arr.data(), arr.size(), [](T p) {
8181
return p.distance();
8282
});
8383
state.PauseTiming();
@@ -89,20 +89,22 @@ static void simdobjsort(benchmark::State &state)
8989
}
9090
}
9191

92-
#define BENCHMARK_OBJSORT(func, T) \
93-
BENCHMARK_TEMPLATE(func, T) \
92+
#define BENCHMARK_OBJSORT(func, T, type, dist) \
93+
BENCHMARK_TEMPLATE(func, T<type,dist>) \
9494
->Arg(10e1) \
9595
->Arg(10e2) \
9696
->Arg(10e3) \
9797
->Arg(10e4) \
9898
->Arg(10e5) \
9999
->Arg(10e6);
100100

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>)
101+
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, x)
102+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, x)
103+
BENCHMARK_OBJSORT(simdobjsort, Point3D, float, x)
104+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, float, x)
105+
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, taxicab )
106+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, taxicab)
107+
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, euclidean)
108+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, euclidean)
109+
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, chebyshev)
110+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, chebyshev)

0 commit comments

Comments
 (0)