Skip to content

Commit

Permalink
add more benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed May 23, 2018
1 parent 48aadd3 commit 403c4e0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
8 changes: 4 additions & 4 deletions benchmark/benchmark_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ namespace xt
}

BENCHMARK_TEMPLATE(assign_c_assign, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xarray<double>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xarray<double, layout_type::dynamic>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xtensor<double, 2, layout_type::dynamic>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_c_assign_ii, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign_ii, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_c_assign_iii, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign_iii, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_xstorageiter_copy, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_xiter_copy, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xarray<double>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xtensor<double, 2>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xarray<double, layout_type::dynamic>)->Range(32, 32<<3);
BENCHMARK_TEMPLATE(assign_x_assign, xt::xtensor<double, 2, layout_type::dynamic>)->Range(32, 32<<3);
}
}

Expand Down
73 changes: 73 additions & 0 deletions benchmark/benchmark_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,77 @@ namespace xt
BENCHMARK_TEMPLATE(math_ref_1, rint_fn)->Range(MATH_RANGE);
BENCHMARK_TEMPLATE(math_xtensor_1, rint_fn, xtensor<double, 2>)->Range(MATH_RANGE);
}

template <class T>
void scalar_assign(benchmark::State& state)
{
T res;
std::size_t sz = static_cast<std::size_t>(state.range(0));
res.resize({sz, sz});
for (auto _ : state)
{
res += typename T::value_type(1);
benchmark::DoNotOptimize(res.data());
}
}

template <class T>
void scalar_assign_ref(benchmark::State& state)
{
T res;
std::size_t sz = static_cast<std::size_t>(state.range(0));
res.resize({sz, sz});
for (auto _ : state)
{
auto szt = res.size();
for (std::size_t i = 0; i < szt; ++i)
{
res.data()[i] += typename T::value_type(1);
}
benchmark::DoNotOptimize(res.data());
}
}

template <class T>
void boolean_func(benchmark::State& state)
{
T a, b;
std::size_t sz = static_cast<std::size_t>(state.range(0));

a.resize({sz, sz});
b.resize({sz, sz});
xtensor<bool, 2> res; res.resize({sz, sz});

for (auto _ : state)
{
res = equal(a, b);
benchmark::DoNotOptimize(res.data());
}
}

template <class T>
void boolean_func_ref(benchmark::State& state)
{
T a, b;
std::size_t sz = static_cast<std::size_t>(state.range(0));

a.resize({sz, sz});
b.resize({sz, sz});
xtensor<bool, 2> res; res.resize({sz, sz});

for (auto _ : state)
{
auto szt = res.size();
for (std::size_t i = 0; i < szt; ++i)
{
res.data()[i] = (a.data()[i] == b.data()[i]);
}
benchmark::DoNotOptimize(res.data());
}
}

BENCHMARK_TEMPLATE(scalar_assign, xtensor<double, 2>)->Range(MATH_RANGE);
BENCHMARK_TEMPLATE(scalar_assign_ref, xtensor<double, 2>)->Range(MATH_RANGE);
BENCHMARK_TEMPLATE(boolean_func, xtensor<double, 2>)->Range(MATH_RANGE);
BENCHMARK_TEMPLATE(boolean_func_ref, xtensor<double, 2>)->Range(MATH_RANGE);
}
6 changes: 1 addition & 5 deletions benchmark/benchmark_xshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace xt
{
for (auto _ : state)
{
T sv({2,3,1});
T sv({2, 3, 1});
benchmark::DoNotOptimize(sv.data());
}
}
Expand Down Expand Up @@ -57,13 +57,9 @@ namespace xt
BENCHMARK_TEMPLATE(xshape_initializer, std::vector<std::size_t>);
BENCHMARK_TEMPLATE(xshape_initializer, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer, std::array<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer_long, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer_long, xt::uvector<std::size_t>);
BENCHMARK_TEMPLATE(xshape_initializer_long, std::vector<std::size_t>);
BENCHMARK_TEMPLATE(xshape_initializer, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer_long, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_initializer, xt::svector<std::size_t, 4>);
BENCHMARK_TEMPLATE(xshape_access, xt::uvector<double>);
BENCHMARK_TEMPLATE(xshape_access, std::vector<double>);
BENCHMARK_TEMPLATE(xshape_access, xt::svector<std::size_t, 4>);
Expand Down

0 comments on commit 403c4e0

Please sign in to comment.