@@ -195,6 +195,76 @@ namespace xt
195195 BENCHMARK_TEMPLATE (view_assign_strided_view_noalias, float );
196196 }
197197
198+ namespace finite_diff
199+ {
200+ inline auto stencil_threedirections (benchmark::State& state, size_t size)
201+ {
202+ for (auto _ : state)
203+ {
204+ const std::array<size_t , 3 > shape = {size, size, size};
205+ xt::xtensor<double , 3 > a (shape), b (shape);
206+ auto core = xt::range (1 , size - 1 );
207+ xt::noalias (xt::view (b, core, core, core)
208+ ) = 1.0 / 7.0
209+ * (xt::view (a, core, core, core) + xt::view (a, core, core, xt::range (2 , size))
210+ + xt::view (a, core, core, xt::range (0 , size - 2 ))
211+ + xt::view (a, core, xt::range (2 , size), core)
212+ + xt::view (a, core, xt::range (0 , size - 2 ), core)
213+ + xt::view (a, xt::range (2 , size), core, core)
214+ + xt::view (a, xt::range (0 , size - 2 ), core, core));
215+ benchmark::DoNotOptimize (b);
216+ }
217+ }
218+
219+ inline auto stencil_twodirections (benchmark::State& state, size_t size)
220+ {
221+ for (auto _ : state)
222+ {
223+ const std::array<size_t , 3 > shape = {size, size, size};
224+ xt::xtensor<double , 3 > a (shape), b (shape);
225+ auto core = xt::range (1 , size - 1 );
226+ xt::noalias (xt::view (b, core, core, core)
227+ ) = 1.0 / 7.0
228+ * (xt::view (a, core, core, core) + xt::view (a, core, xt::range (2 , size), core)
229+ + xt::view (a, core, xt::range (0 , size - 2 ), core)
230+ + xt::view (a, xt::range (2 , size), core, core)
231+ + xt::view (a, xt::range (0 , size - 2 ), core, core));
232+ benchmark::DoNotOptimize (b);
233+ }
234+ }
235+
236+ inline auto stencil_onedirection (benchmark::State& state, size_t size)
237+ {
238+ for (auto _ : state)
239+ {
240+ const std::array<size_t , 3 > shape = {size, size, size};
241+ xt::xtensor<double , 3 > a (shape), b (shape);
242+ auto core = xt::range (1 , size - 1 );
243+ xt::noalias (xt::view (b, core, core, core)
244+ ) = 1.0 / 2.0
245+ * (xt::view (a, xt::range (2 , size), core, core)
246+ - xt::view (a, xt::range (0 , size - 2 ), core, core));
247+ benchmark::DoNotOptimize (b);
248+ }
249+ }
250+
251+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_50, 50 );
252+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_100, 100 );
253+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_200, 200 );
254+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_300, 300 );
255+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_500, 500 );
256+ BENCHMARK_CAPTURE (stencil_twodirections, stencil_twodirections_50, 50 );
257+ BENCHMARK_CAPTURE (stencil_twodirections, stencil_twodirections_100, 100 );
258+ BENCHMARK_CAPTURE (stencil_twodirections, stencil_twodirections_200, 200 );
259+ BENCHMARK_CAPTURE (stencil_twodirections, stencil_twodirections_300, 300 );
260+ BENCHMARK_CAPTURE (stencil_twodirections, stencil_twodirections_500, 500 );
261+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_50, 50 );
262+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_100, 100 );
263+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_200, 200 );
264+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_300, 300 );
265+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_500, 500 );
266+ }
267+
198268 namespace stridedview
199269 {
200270
0 commit comments