Skip to content

Commit 8a20c82

Browse files
committed
feat : improve benchmark
1 parent 9038fa1 commit 8a20c82

File tree

5 files changed

+352
-328
lines changed

5 files changed

+352
-328
lines changed

benchmark/benchmark_cellarray.cpp

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <array>
32
#include <benchmark/benchmark.h>
43
#include <cmath>
@@ -23,39 +22,49 @@
2322
///////////////////////////////////////////////////////////////////
2423
// utils
2524

25+
constexpr int DEFAULT_X_INTERVALS = 5; // nombre d'intervalles en X pour les cas 2D/3D
26+
2627
template <unsigned int dim>
27-
auto gen_regular_intervals = [](int64_t size, unsigned int level = 0)
28+
auto gen_regular_intervals = [](int max_index, unsigned int level = 0, int x_intervals = DEFAULT_X_INTERVALS)
2829
{
2930
samurai::CellList<dim> cl;
3031

31-
for (int64_t i = 0; i < size; i++)
32-
{
33-
int index = static_cast<int>(i);
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;
32+
int interval_size = 1 << level; // 2^level
33+
int spacing = 1 << (level + 1); // 2^(level+1)
4134

42-
if constexpr (dim == 1)
35+
if constexpr (dim == 1)
36+
{
37+
// En 1D on garde le comportement précédent : un intervalle par abscisse.
38+
for (int x = 0; x < max_index; ++x)
4339
{
44-
cl[level][{}].add_interval({start, end});
40+
int start = x * spacing;
41+
cl[level][{}].add_interval({start, start + interval_size});
4542
}
46-
else if constexpr (dim == 2)
43+
}
44+
else if constexpr (dim == 2)
45+
{
46+
int nx = x_intervals;
47+
for (int x = 0; x < nx; ++x)
4748
{
48-
for (int y = 0; y < size; ++y)
49+
int start = x * spacing;
50+
int end = start + interval_size;
51+
for (int y = 0; y < max_index; ++y)
4952
{
5053
xt::xtensor_fixed<int, xt::xshape<1>> coord{y};
5154
cl[level][coord].add_interval({start, end});
5255
}
5356
}
54-
else if constexpr (dim == 3)
57+
}
58+
else if constexpr (dim == 3)
59+
{
60+
int nx = x_intervals;
61+
for (int x = 0; x < nx; ++x)
5562
{
56-
for (int y = 0; y < size; ++y)
63+
int start = x * spacing;
64+
int end = start + interval_size;
65+
for (int y = 0; y < max_index; ++y)
5766
{
58-
for (int z = 0; z < size; ++z)
67+
for (int z = 0; z < max_index; ++z)
5968
{
6069
xt::xtensor_fixed<int, xt::xshape<2>> coord{y, z};
6170
cl[level][coord].add_interval({start, end});
@@ -68,9 +77,9 @@ auto gen_regular_intervals = [](int64_t size, unsigned int level = 0)
6877
};
6978

7079
template <unsigned int dim>
71-
auto cell_array_with_n_intervals(int64_t size)
80+
auto cell_array_with_n_intervals(int max_index)
7281
{
73-
auto cl = gen_regular_intervals<dim>(size);
82+
auto cl = gen_regular_intervals<dim>(max_index, 0, DEFAULT_X_INTERVALS);
7483
samurai::CellArray<dim> ca(cl);
7584
return ca;
7685
}
@@ -91,10 +100,23 @@ void CELLARRAY_default(benchmark::State& state)
91100
template <unsigned int dim>
92101
void CELLARRAY_cl_ca_multi(benchmark::State& state)
93102
{
94-
auto cl = gen_regular_intervals<dim>(state.range(0));
103+
int max_index = static_cast<int>(state.range(0));
104+
auto cl = gen_regular_intervals<dim>(max_index, 0, DEFAULT_X_INTERVALS);
95105

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));
106+
// Calculer le nombre d'intervalles selon la nouvelle logique
107+
std::size_t nb_intervals;
108+
if constexpr (dim == 1)
109+
{
110+
nb_intervals = max_index;
111+
}
112+
else if constexpr (dim == 2)
113+
{
114+
nb_intervals = DEFAULT_X_INTERVALS * max_index;
115+
}
116+
else if constexpr (dim == 3)
117+
{
118+
nb_intervals = DEFAULT_X_INTERVALS * max_index * max_index;
119+
}
98120

99121
for (auto _ : state)
100122
{
@@ -162,9 +184,9 @@ BENCHMARK_TEMPLATE(CELLARRAY_default, 1, 12);
162184
BENCHMARK_TEMPLATE(CELLARRAY_default, 2, 12);
163185
BENCHMARK_TEMPLATE(CELLARRAY_default, 3, 12);
164186

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);
187+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 1)->RangeMultiplier(8)->Range(1 << 1, 10000);
188+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 2)->RangeMultiplier(4)->Range(1 << 1, 2000);
189+
BENCHMARK_TEMPLATE(CELLARRAY_cl_ca_multi, 3)->RangeMultiplier(2)->Range(1 << 1, 45);
168190

169191
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 1)->Arg(15);
170192
BENCHMARK_TEMPLATE(CELLARRAY_min_level, 2)->Arg(15);

benchmark/benchmark_celllist_construction.cpp

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,49 @@
99
////////////////////////////////////////////////////////////
1010
/// Générateur d'intervalles réguliers (adapté de benchmark_search.cpp)
1111

12+
constexpr int DEFAULT_X_INTERVALS = 5; // nombre d'intervalles en X pour les cas 2D/3D
13+
1214
template <unsigned int dim>
13-
auto gen_regular_intervals = [](int64_t size, unsigned int level = 0)
15+
auto gen_regular_intervals = [](int max_index, unsigned int level = 0, int x_intervals = DEFAULT_X_INTERVALS)
1416
{
1517
samurai::CellList<dim> cl;
1618

17-
for (int64_t i = 0; i < size; i++)
18-
{
19-
int index = static_cast<int>(i);
20-
21-
// Calcul des paramètres selon le niveau :
22-
// Niveau L : taille = 2^L, espacement = 2^(L+1)
23-
int interval_size = 1 << level; // 2^level
24-
int spacing = 1 << (level + 1); // 2^(level+1)
25-
int start = index * spacing;
26-
int end = start + interval_size;
19+
int interval_size = 1 << level; // 2^level
20+
int spacing = 1 << (level + 1); // 2^(level+1)
2721

28-
if constexpr (dim == 1)
22+
if constexpr (dim == 1)
23+
{
24+
// En 1D on garde le comportement précédent : un intervalle par abscisse.
25+
for (int x = 0; x < max_index; ++x)
2926
{
30-
cl[level][{}].add_interval({start, end});
27+
int start = x * spacing;
28+
cl[level][{}].add_interval({start, start + interval_size});
3129
}
32-
else if constexpr (dim == 2)
30+
}
31+
else if constexpr (dim == 2)
32+
{
33+
int nx = x_intervals;
34+
for (int x = 0; x < nx; ++x)
3335
{
34-
for (int y = 0; y < size; ++y)
36+
int start = x * spacing;
37+
int end = start + interval_size;
38+
for (int y = 0; y < max_index; ++y)
3539
{
3640
xt::xtensor_fixed<int, xt::xshape<1>> coord{y};
3741
cl[level][coord].add_interval({start, end});
3842
}
3943
}
40-
else if constexpr (dim == 3)
44+
}
45+
else if constexpr (dim == 3)
46+
{
47+
int nx = x_intervals;
48+
for (int x = 0; x < nx; ++x)
4149
{
42-
for (int y = 0; y < size; ++y)
50+
int start = x * spacing;
51+
int end = start + interval_size;
52+
for (int y = 0; y < max_index; ++y)
4353
{
44-
for (int z = 0; z < size; ++z)
54+
for (int z = 0; z < max_index; ++z)
4555
{
4656
xt::xtensor_fixed<int, xt::xshape<2>> coord{y, z};
4757
cl[level][coord].add_interval({start, end});
@@ -119,13 +129,14 @@ void CELLLIST_default(benchmark::State& state)
119129
template <unsigned int dim>
120130
void CELLLIST_add_interval_begin(benchmark::State& state)
121131
{
132+
int max_index = static_cast<int>(state.range(0));
122133
// Calculer une seule fois pour les métriques
123-
auto cl_sample = gen_regular_intervals<dim>(state.range(0), 0);
134+
auto cl_sample = gen_regular_intervals<dim>(max_index, 0, DEFAULT_X_INTERVALS);
124135
std::size_t total_intervals = count_intervals<dim>(cl_sample);
125136

126137
for (auto _ : state)
127138
{
128-
auto cl = gen_regular_intervals<dim>(state.range(0), 0);
139+
auto cl = gen_regular_intervals<dim>(max_index, 0, DEFAULT_X_INTERVALS);
129140
benchmark::DoNotOptimize(cl);
130141
}
131142

@@ -139,7 +150,8 @@ void CELLLIST_add_interval_begin(benchmark::State& state)
139150
template <unsigned int dim>
140151
void CELLLIST_copy_assignment(benchmark::State& state)
141152
{
142-
auto source_cl = gen_regular_intervals<dim>(state.range(0), 0);
153+
int max_index = static_cast<int>(state.range(0));
154+
auto source_cl = gen_regular_intervals<dim>(max_index, 0, DEFAULT_X_INTERVALS);
143155
std::size_t total_intervals = count_intervals<dim>(source_cl);
144156

145157
for (auto _ : state)
@@ -163,11 +175,11 @@ BENCHMARK_TEMPLATE(CELLLIST_default, 1);
163175
BENCHMARK_TEMPLATE(CELLLIST_default, 2);
164176
BENCHMARK_TEMPLATE(CELLLIST_default, 3);
165177

166-
// Générateur avec intervalles réguliers (toutes dimensions)
167-
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 1)->RangeMultiplier(64)->Range(1 << 1, 1 << 16);
168-
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 2)->RangeMultiplier(8)->Range(1 << 1, 1 << 8);
169-
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 3)->RangeMultiplier(4)->Range(1 << 1, 1 << 5);
178+
// Générateur avec intervalles réguliers (toutes dimensions) - Ajusté pour ~10k intervalles max
179+
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 1)->RangeMultiplier(64)->Range(1 << 1, 10000);
180+
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 2)->RangeMultiplier(8)->Range(1 << 1, 2000);
181+
BENCHMARK_TEMPLATE(CELLLIST_add_interval_begin, 3)->RangeMultiplier(4)->Range(1 << 1, 45);
170182

171-
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 1)->RangeMultiplier(64)->Range(1 << 1, 1 << 16);
172-
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 2)->RangeMultiplier(8)->Range(1 << 1, 1 << 8);
173-
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 3)->RangeMultiplier(4)->Range(1 << 1, 1 << 5);
183+
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 1)->RangeMultiplier(64)->Range(1 << 1, 10000);
184+
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 2)->RangeMultiplier(8)->Range(1 << 1, 2000);
185+
BENCHMARK_TEMPLATE(CELLLIST_copy_assignment, 3)->RangeMultiplier(4)->Range(1 << 1, 45);

0 commit comments

Comments
 (0)