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>
29struct  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