@@ -5,19 +5,19 @@ static constexpr char euclidean[] = "euclidean";
5
5
static constexpr char taxicab[] = " taxicab" ;
6
6
static constexpr char chebyshev[] = " chebyshev" ;
7
7
8
- template <const char * val>
8
+ template <typename T, const char * val>
9
9
struct Point3D {
10
- double x;
11
- double y;
12
- double z;
10
+ T x;
11
+ T y;
12
+ T z;
13
13
static constexpr std::string_view name {val};
14
14
Point3D ()
15
15
{
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;
19
19
}
20
- double distance ()
20
+ T distance ()
21
21
{
22
22
if constexpr (name == " x" ) {
23
23
return x;
@@ -77,7 +77,7 @@ static void simdobjsort(benchmark::State &state)
77
77
std::vector<T> arr_bkp = arr;
78
78
// benchmark
79
79
for (auto _ : state) {
80
- x86simdsort::object_qsort (arr.data (), arr.size (), [](T p) -> double {
80
+ x86simdsort::object_qsort (arr.data (), arr.size (), [](T p) {
81
81
return p.distance ();
82
82
});
83
83
state.PauseTiming ();
@@ -89,20 +89,22 @@ static void simdobjsort(benchmark::State &state)
89
89
}
90
90
}
91
91
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> ) \
94
94
->Arg(10e1 ) \
95
95
->Arg(10e2 ) \
96
96
->Arg(10e3 ) \
97
97
->Arg(10e4 ) \
98
98
->Arg(10e5 ) \
99
99
->Arg(10e6 );
100
100
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