APM:Libraries
benchmark_geodesic_grid.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Intel Corporation. All rights reserved.
3  *
4  * This file is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <AP_gbenchmark.h>
18 
20 
21 static const Vector3f triangles[20][3] = {
22  {{-M_GOLDEN, 1, 0}, {-1, 0,-M_GOLDEN}, {-M_GOLDEN,-1, 0}},
23  {{-1, 0,-M_GOLDEN}, {-M_GOLDEN,-1, 0}, { 0,-M_GOLDEN,-1}},
24  {{-M_GOLDEN,-1, 0}, { 0,-M_GOLDEN,-1}, { 0,-M_GOLDEN, 1}},
25  {{-1, 0,-M_GOLDEN}, { 0,-M_GOLDEN,-1}, { 1, 0,-M_GOLDEN}},
26  {{ 0,-M_GOLDEN,-1}, { 0,-M_GOLDEN, 1}, { M_GOLDEN,-1, 0}},
27  {{ 0,-M_GOLDEN,-1}, { 1, 0,-M_GOLDEN}, { M_GOLDEN,-1, 0}},
28  {{ M_GOLDEN,-1, 0}, { 1, 0,-M_GOLDEN}, { M_GOLDEN, 1, 0}},
29  {{ 1, 0,-M_GOLDEN}, { M_GOLDEN, 1, 0}, { 0, M_GOLDEN,-1}},
30  {{ 1, 0,-M_GOLDEN}, { 0, M_GOLDEN,-1}, {-1, 0,-M_GOLDEN}},
31  {{ 0, M_GOLDEN,-1}, {-M_GOLDEN, 1, 0}, {-1, 0,-M_GOLDEN}},
32 
33  {{ M_GOLDEN,-1, 0}, { 1, 0, M_GOLDEN}, { M_GOLDEN, 1, 0}},
34  {{ 1, 0, M_GOLDEN}, { M_GOLDEN, 1, 0}, { 0, M_GOLDEN, 1}},
35  {{ M_GOLDEN, 1, 0}, { 0, M_GOLDEN, 1}, { 0, M_GOLDEN,-1}},
36  {{ 1, 0, M_GOLDEN}, { 0, M_GOLDEN, 1}, {-1, 0, M_GOLDEN}},
37  {{ 0, M_GOLDEN, 1}, { 0, M_GOLDEN,-1}, {-M_GOLDEN, 1, 0}},
38  {{ 0, M_GOLDEN, 1}, {-1, 0, M_GOLDEN}, {-M_GOLDEN, 1, 0}},
39  {{-M_GOLDEN, 1, 0}, {-1, 0, M_GOLDEN}, {-M_GOLDEN,-1, 0}},
40  {{-1, 0, M_GOLDEN}, {-M_GOLDEN,-1, 0}, { 0,-M_GOLDEN, 1}},
41  {{-1, 0, M_GOLDEN}, { 0,-M_GOLDEN, 1}, { 1, 0, M_GOLDEN}},
42  {{ 0,-M_GOLDEN, 1}, { M_GOLDEN,-1, 0}, { 1, 0, M_GOLDEN}},
43 };
44 
45 static bool section_triangle(unsigned int section_index,
46  Vector3f& a,
47  Vector3f& b,
48  Vector3f& c) {
49  if (section_index >= 80) {
50  return false;
51  }
52 
53  unsigned int i = section_index / 4;
54  unsigned int j = section_index % 4;
55  auto& t = triangles[i];
56  Vector3f mt[3]{(t[0] + t[1]) / 2, (t[1] + t[2]) / 2, (t[2] + t[0]) / 2};
57 
58  switch (j) {
59  case 0:
60  a = mt[0];
61  b = mt[1];
62  c = mt[2];
63  break;
64  case 1:
65  a = t[0];
66  b = mt[0];
67  c = mt[2];
68  break;
69  case 2:
70  a = mt[0];
71  b = t[1];
72  c = mt[1];
73  break;
74  case 3:
75  a = mt[2];
76  b = mt[1];
77  c = t[2];
78  break;
79  }
80 
81  return true;
82 }
83 
84 static void BM_GeodesicGridSections(benchmark::State& state)
85 {
86  Vector3f v, a, b, c;
87  int section = state.range_x();
88 
89  section_triangle(section, a, b, c);
90  v = (a + b + c) / 3.0f;
91 
92  while (state.KeepRunning()) {
93  int s = AP_GeodesicGrid::section(v);
94  gbenchmark_escape(&s);
95  }
96 }
97 
98 /* Benchmark each section */
99 BENCHMARK(BM_GeodesicGridSections)->DenseRange(0, 79);
100 
101 BENCHMARK_MAIN()
static const Vector3f triangles[20][3]
#define M_GOLDEN
Definition: definitions.h:17
BENCHMARK(BM_GeodesicGridSections) -> DenseRange(0, 79)
#define f(i)
static int state
Definition: Util.cpp:20
float v
Definition: Printf.cpp:15
static int section(const Vector3f &v, bool inclusive=false)
static bool section_triangle(unsigned int section_index, Vector3f &a, Vector3f &b, Vector3f &c)
static void BM_GeodesicGridSections(benchmark::State &state)