@@ -195,6 +195,54 @@ 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_onedirection (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 / 2.0
228+ * (xt::view (a, xt::range (2 , size), core, core)
229+ - xt::view (a, xt::range (0 , size - 2 ), core, core));
230+ benchmark::DoNotOptimize (b);
231+ }
232+ }
233+
234+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_50, 50 );
235+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_100, 100 );
236+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_200, 200 );
237+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_300, 300 );
238+ BENCHMARK_CAPTURE (stencil_threedirections, stencil_threedirections_500, 500 );
239+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_50, 50 );
240+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_100, 100 );
241+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_200, 200 );
242+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_300, 300 );
243+ BENCHMARK_CAPTURE (stencil_onedirection, stencil_onedirections_500, 500 );
244+ }
245+
198246 namespace stridedview
199247 {
200248
0 commit comments