Skip to content

Commit f02a1b2

Browse files
committed
feat: update bechmarks
1 parent 909b23f commit f02a1b2

11 files changed

+1529
-1024
lines changed

benchmark/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ find_package(Threads)
2222
set(SAMURAI_BENCHMARKS
2323
benchmark_celllist_construction.cpp
2424
benchmark_search.cpp
25-
benchmark_set.cpp
2625
benchmark_interval.cpp
2726
benchmark_cellarray.cpp
2827
benchmark_level_cell_array.cpp

benchmark/benchmark_bc.cpp

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,46 +51,21 @@ template <unsigned int dim, unsigned int n_comp, typename BCType, unsigned int o
5151
void BC_homogeneous(benchmark::State& state)
5252
{
5353
samurai::Box<double, dim> box = unitary_box<dim>();
54-
using Config = samurai::UniformConfig<dim, order>; // Utilisation de l'ordre comme paramètre
55-
auto mesh = samurai::UniformMesh<Config>(box, state.range(0));
56-
auto u = make_field<double, n_comp>("u", mesh);
57-
58-
u.fill(1.0);
59-
60-
for (auto _ : state)
61-
{
62-
samurai::make_bc<BCType>(u);
63-
}
64-
}
54+
using Config = samurai::UniformConfig<dim, order>; // Utilisation de l'ordre comme paramètre
55+
auto mesh = samurai::UniformMesh<Config>(box, state.range(0));
56+
auto u = make_field<double, n_comp>("u", mesh);
6557

66-
// Test BC sur une direction spécifique
67-
template <unsigned int dim, unsigned int n_comp, typename BCType, unsigned int order>
68-
void BC_directional(benchmark::State& state)
69-
{
70-
samurai::Box<double, dim> box = unitary_box<dim>();
71-
using Config = samurai::UniformConfig<dim, order>;
72-
auto mesh = samurai::UniformMesh<Config>(box, state.range(0));
73-
auto u = make_field<double, n_comp>("u", mesh);
74-
7558
u.fill(1.0);
76-
59+
60+
// Ajout des compteurs personnalisés
61+
state.counters["Dimension"] = dim;
62+
state.counters["Composantes"] = n_comp;
63+
state.counters["Ordre"] = order;
64+
state.counters["Type BC"] = std::is_same_v<BCType, samurai::Dirichlet<dim>> ? 0 : 1; // 0 pour Dirichlet, 1 pour Neumann
65+
7766
for (auto _ : state)
7867
{
79-
if constexpr (dim == 1)
80-
{
81-
const xt::xtensor_fixed<int, xt::xshape<1>> left{-1};
82-
samurai::make_bc<BCType>(u)->on(left);
83-
}
84-
else if constexpr (dim == 2)
85-
{
86-
const xt::xtensor_fixed<int, xt::xshape<2>> left{-1, 0};
87-
samurai::make_bc<BCType>(u)->on(left);
88-
}
89-
else if constexpr (dim == 3)
90-
{
91-
const xt::xtensor_fixed<int, xt::xshape<3>> left{-1, 0, 0};
92-
samurai::make_bc<BCType>(u)->on(left);
93-
}
68+
samurai::make_bc<BCType>(u);
9469
}
9570
}
9671

@@ -111,12 +86,3 @@ BENCHMARK_TEMPLATE(BC_homogeneous, 1, 1, samurai::Dirichlet<2>, 3)->DenseRange(1
11186
BENCHMARK_TEMPLATE(BC_homogeneous, 2, 1, samurai::Dirichlet<2>, 3)->DenseRange(1, 1);
11287
BENCHMARK_TEMPLATE(BC_homogeneous, 3, 1, samurai::Dirichlet<2>, 3)->DenseRange(1, 1);
11388
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 100, samurai::Dirichlet<2>, 3)->DenseRange(1, 1);
114-
115-
// BC directionnels
116-
BENCHMARK_TEMPLATE(BC_directional, 1, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
117-
BENCHMARK_TEMPLATE(BC_directional, 2, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
118-
BENCHMARK_TEMPLATE(BC_directional, 3, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
119-
120-
121-
122-

benchmark/benchmark_cell.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ auto make_cell()
2424
{
2525
using value_t = samurai::default_config::value_t;
2626
using point_t = xt::xtensor_fixed<value_t, xt::xshape<dim>>;
27-
27+
2828
// Initialisation générique des indices et du point de départ
2929
point_t indice = xt::ones<value_t>({dim});
30-
point_t begin = xt::zeros<value_t>({dim});
31-
32-
auto indices = xt::xtensor_fixed<int, xt::xshape<dim>>(indice);
30+
point_t begin = xt::zeros<value_t>({dim});
31+
32+
auto indices = xt::xtensor_fixed<int, xt::xshape<dim>>(indice);
3333
double scaling_factor = 1.0;
34-
return samurai::Cell<dim, samurai::Interval<int>>(begin, scaling_factor, 1, indices, 0);
34+
auto c = samurai::Cell<dim, samurai::Interval<int>>(begin, scaling_factor, 1, indices, 0);
35+
return c;
3536
}
3637

3738
// Mesure : Construction d'une cellule par défaut
38-
// Cette fonction mesure le temps nécessaire pour créer une cellule sans paramètres
3939
template <unsigned int dim>
4040
void CELL_default(benchmark::State& state)
4141
{
@@ -121,7 +121,6 @@ void CELL_corner(benchmark::State& state)
121121
}
122122

123123
// Mesure : Test d'égalité entre deux cellules
124-
// Cette fonction mesure le temps nécessaire pour comparer deux cellules identiques
125124
template <unsigned int dim>
126125
void CELL_equal(benchmark::State& state)
127126
{

benchmark/benchmark_cellarray.cpp

Lines changed: 69 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#include <array>
33
#include <benchmark/benchmark.h>
4+
#include <cmath>
45
#include <experimental/random>
56

67
#include <xtensor/xfixed.hpp>
@@ -23,21 +24,53 @@
2324
// utils
2425

2526
template <unsigned int dim>
26-
auto cell_list_with_n_intervals(int64_t size)
27+
auto gen_regular_intervals = [](int64_t size, unsigned int level = 0)
2728
{
2829
samurai::CellList<dim> cl;
30+
2931
for (int64_t i = 0; i < size; i++)
3032
{
3133
int index = static_cast<int>(i);
32-
cl[0][{}].add_interval({2 * index, 2 * index + 1});
34+
35+
// Calcul des paramètres selon le niveau :
36+
// Niveau L : taille = 2^L, espacement = 2^(L+1)
37+
int interval_size = 1 << level; // 2^level
38+
int spacing = 1 << (level + 1); // 2^(level+1)
39+
int start = index * spacing;
40+
int end = start + interval_size;
41+
42+
if constexpr (dim == 1)
43+
{
44+
cl[level][{}].add_interval({start, end});
45+
}
46+
else if constexpr (dim == 2)
47+
{
48+
for (int y = 0; y < size; ++y)
49+
{
50+
xt::xtensor_fixed<int, xt::xshape<1>> coord{y};
51+
cl[level][coord].add_interval({start, end});
52+
}
53+
}
54+
else if constexpr (dim == 3)
55+
{
56+
for (int y = 0; y < size; ++y)
57+
{
58+
for (int z = 0; z < size; ++z)
59+
{
60+
xt::xtensor_fixed<int, xt::xshape<2>> coord{y, z};
61+
cl[level][coord].add_interval({start, end});
62+
}
63+
}
64+
}
3365
}
66+
3467
return cl;
35-
}
68+
};
3669

3770
template <unsigned int dim>
3871
auto cell_array_with_n_intervals(int64_t size)
3972
{
40-
auto cl = cell_list_with_n_intervals<dim>(size);
73+
auto cl = gen_regular_intervals<dim>(size);
4174
samurai::CellArray<dim> ca(cl);
4275
return ca;
4376
}
@@ -58,19 +91,30 @@ void CELLARRAY_default(benchmark::State& state)
5891
template <unsigned int dim>
5992
void CELLARRAY_cl_ca_multi(benchmark::State& state)
6093
{
61-
auto cl = cell_list_with_n_intervals<dim>(state.range(0));
94+
auto cl = gen_regular_intervals<dim>(state.range(0));
95+
96+
// Le nombre d'intervalles est state.range(0)^dim
97+
std::size_t nb_intervals = static_cast<std::size_t>(std::pow(state.range(0), dim));
98+
6299
for (auto _ : state)
63100
{
64101
samurai::CellArray<dim> ca(cl);
65102
benchmark::DoNotOptimize(ca[0]);
66103
}
104+
105+
// Ajouter les compteurs
106+
state.counters["nb_intervals"] = nb_intervals;
107+
state.counters["ns/interval"] = benchmark::Counter(nb_intervals,
108+
benchmark::Counter::kIsIterationInvariantRate | benchmark::Counter::kInvert);
109+
state.counters["dim"] = dim;
67110
}
68111

69112
// Mesure : Récupération du niveau bas d'un CellList
70113
template <unsigned int dim>
71114
void CELLARRAY_min_level(benchmark::State& state)
72115
{
73116
samurai::CellList<dim> cl;
117+
74118
cl[state.range(0)][{}].add_interval({0, 1});
75119
samurai::CellArray<dim> ca(cl);
76120
for (auto _ : state)
@@ -85,7 +129,10 @@ template <unsigned int dim>
85129
void CELLARRAY_begin(benchmark::State& state)
86130
{
87131
samurai::CellList<dim> cl;
88-
cl[state.range(0)][{}].add_interval({0, 1});
132+
for (int level = 0; level <= state.range(0); ++level)
133+
{
134+
cl[level][{}].add_interval({0, 1});
135+
}
89136
samurai::CellArray<dim> ca(cl);
90137
for (auto _ : state)
91138
{
@@ -99,141 +146,34 @@ template <unsigned int dim>
99146
void CELLARRAY_end(benchmark::State& state)
100147
{
101148
samurai::CellList<dim> cl;
102-
cl[state.range(0)][{}].add_interval({0, 1});
103-
samurai::CellArray<dim> ca(cl);
104-
for (auto _ : state)
149+
for (int level = 0; level <= state.range(0); ++level)
105150
{
106-
auto end = ca.end();
107-
benchmark::DoNotOptimize(end);
151+
cl[level][{}].add_interval({0, 1});
108152
}
109-
}
110-
111-
// Mesure : Récupération de l'itérateur reverse begin d'un CellArray
112-
template <unsigned int dim>
113-
void CELLARRAY_rbegin(benchmark::State& state)
114-
{
115-
samurai::CellList<dim> cl;
116-
cl[state.range(0)][{}].add_interval({0, 1});
117153
samurai::CellArray<dim> ca(cl);
118154
for (auto _ : state)
119155
{
120-
auto rbegin = ca.rbegin();
121-
benchmark::DoNotOptimize(rbegin);
122-
}
123-
}
124-
125-
// Mesure : Création d'un CellArray 2D à partid d'un CellList composé de n intervalles aléatoires
126-
// Ressemble à CELLARRAY_cl_ca_multi
127-
static void CELLARRAY_CellList2CellArray_2D(benchmark::State& state)
128-
{
129-
constexpr std::size_t dim = 2;
130-
131-
std::size_t min_level = 1;
132-
std::size_t max_level = 12;
133-
134-
samurai::CellList<dim> cl;
135-
samurai::CellArray<dim> ca;
136-
137-
for (std::size_t s = 0; s < state.range(0); ++s)
138-
{
139-
auto level = std::experimental::randint(min_level, max_level);
140-
auto x = std::experimental::randint(0, (100 << level) - 1);
141-
auto y = std::experimental::randint(0, (100 << level) - 1);
142-
143-
cl[level][{y}].add_point(x);
144-
}
145-
146-
for (auto _ : state)
147-
{
148-
ca = {cl};
149-
}
150-
}
151-
152-
BENCHMARK(CELLARRAY_CellList2CellArray_2D)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
153-
154-
// Mesure : Création d'un CellArray 3D à partid d'un CellList composé de n intervalles aléatoires
155-
// Ressemble à CELLARRAY_cl_ca_multi
156-
static void CELLARRAY_CellList2CellArray_3D(benchmark::State& state)
157-
{
158-
constexpr std::size_t dim = 3;
159-
160-
std::size_t min_level = 1;
161-
std::size_t max_level = 12;
162-
163-
samurai::CellList<dim> cl;
164-
samurai::CellArray<dim> ca;
165-
166-
for (std::size_t s = 0; s < state.range(0); ++s)
167-
{
168-
auto level = std::experimental::randint(min_level, max_level);
169-
auto x = std::experimental::randint(0, (100 << level) - 1);
170-
auto y = std::experimental::randint(0, (100 << level) - 1);
171-
auto z = std::experimental::randint(0, (100 << level) - 1);
172-
173-
cl[level][{y, z}].add_point(x);
174-
}
175-
176-
for (auto _ : state)
177-
{
178-
ca = {cl};
179-
}
180-
}
181-
182-
BENCHMARK(CELLARRAY_CellList2CellArray_3D)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
183-
184-
// Mesure : Comparaison "=" entre deux CellArray aléatoires
185-
// On ne devrait pas utiliser un CellArray aléatoire.
186-
static void CELLARRAY_equal_2D(benchmark::State& state)
187-
{
188-
constexpr std::size_t dim = 2;
189-
190-
std::size_t min_level = 1;
191-
std::size_t max_level = 12;
192-
193-
samurai::CellList<dim> cl;
194-
samurai::CellArray<dim> ca;
195-
samurai::CellArray<dim> ca2;
196-
197-
for (std::size_t s = 0; s < state.range(0); ++s)
198-
{
199-
auto level = std::experimental::randint(min_level, max_level);
200-
auto x = std::experimental::randint(0, (100 << level) - 1);
201-
auto y = std::experimental::randint(0, (100 << level) - 1);
202-
203-
cl[level][{y}].add_point(x);
204-
}
205-
ca = {cl};
206-
ca2 = {cl};
207-
208-
for (auto _ : state)
209-
{
210-
auto equal = ca == ca2;
211-
benchmark::DoNotOptimize(equal);
156+
auto end = ca.end();
157+
benchmark::DoNotOptimize(end);
212158
}
213159
}
214160

215-
BENCHMARK(CELLARRAY_equal_2D)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
216-
217161
BENCHMARK_TEMPLATE(CELLARRAY_default, 1, 12);
218162
BENCHMARK_TEMPLATE(CELLARRAY_default, 2, 12);
219163
BENCHMARK_TEMPLATE(CELLARRAY_default, 3, 12);
220164

221-
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 1)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
222-
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 2)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
223-
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 3)->RangeMultiplier(2)->Range(1 << 1, 1 << 10);
224-
225-
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 1)->DenseRange(0, 15);
226-
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 2)->DenseRange(0, 15);
227-
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 3)->DenseRange(0, 15);
165+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 1)->RangeMultiplier(8)->Range(1 << 1, 1 << 10);
166+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 2)->RangeMultiplier(4)->Range(1 << 1, 1 << 6);
167+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 3)->RangeMultiplier(2)->Range(1 << 1, 1 << 4);
228168

229-
BENCHMARK_TEMPLATE(CELLARRAY_begin, 1)->DenseRange(0, 15);
230-
BENCHMARK_TEMPLATE(CELLARRAY_begin, 2)->DenseRange(0, 15);
231-
BENCHMARK_TEMPLATE(CELLARRAY_begin, 3)->DenseRange(0, 15);
169+
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 1)->Arg(15);
170+
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 2)->Arg(15);
171+
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 3)->Arg(15);
232172

233-
BENCHMARK_TEMPLATE(CELLARRAY_rbegin, 1)->DenseRange(0, 15);
234-
BENCHMARK_TEMPLATE(CELLARRAY_rbegin, 2)->DenseRange(0, 15);
235-
BENCHMARK_TEMPLATE(CELLARRAY_rbegin, 3)->DenseRange(0, 15);
173+
BENCHMARK_TEMPLATE(CELLARRAY_begin, 1)->Arg(15);
174+
BENCHMARK_TEMPLATE(CELLARRAY_begin, 2)->Arg(15);
175+
BENCHMARK_TEMPLATE(CELLARRAY_begin, 3)->Arg(15);
236176

237-
BENCHMARK_TEMPLATE(CELLARRAY_end, 1)->DenseRange(0, 15);
238-
BENCHMARK_TEMPLATE(CELLARRAY_end, 2)->DenseRange(0, 15);
239-
BENCHMARK_TEMPLATE(CELLARRAY_end, 3)->DenseRange(0, 15);
177+
BENCHMARK_TEMPLATE(CELLARRAY_end, 1)->Arg(15);
178+
BENCHMARK_TEMPLATE(CELLARRAY_end, 2)->Arg(15);
179+
BENCHMARK_TEMPLATE(CELLARRAY_end, 3)->Arg(15);

0 commit comments

Comments
 (0)