forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_increment_stepper.cpp
More file actions
72 lines (63 loc) · 2.58 KB
/
benchmark_increment_stepper.cpp
File metadata and controls
72 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include <benchmark/benchmark.h>
#include "xtensor/containers/xarray.hpp"
#include "xtensor/generators/xrandom.hpp"
#define SHAPE 30, 30
#define RANGE 3, 100
namespace xt
{
namespace benchmark_xstepper
{
void stepper_stepper(benchmark::State& state)
{
std::vector<std::size_t> shape = {SHAPE, std::size_t(state.range(0))};
xt::xarray<double> a = xt::random::rand<double>(shape);
xt::xarray<double> b = xt::random::rand<double>(shape);
volatile double c = 0;
for (auto _ : state)
{
auto end = compute_size(shape);
auto it = a.stepper_begin(shape);
auto bit = b.stepper_begin(shape);
xindex index(shape.size());
xindex bindex(shape.size());
for (std::size_t i = 0; i < end; ++i)
{
c += *it + *bit;
stepper_tools<layout_type::row_major>::increment_stepper(bit, bindex, shape);
stepper_tools<layout_type::row_major>::increment_stepper(it, index, shape);
}
benchmark::DoNotOptimize(c);
}
}
BENCHMARK(stepper_stepper)->Range(RANGE);
void stepper_stepper_ref(benchmark::State& state)
{
std::vector<std::size_t> shape = {SHAPE, std::size_t(state.range(0))};
xt::xarray<double> a = xt::random::rand<double>(shape);
xt::xarray<double> b = xt::random::rand<double>(shape);
xindex index;
xindex bindex;
volatile double c = 0;
for (auto _ : state)
{
auto it = a.storage().begin();
auto bit = b.storage().begin();
auto end = a.storage().end();
for (; it != end; ++it)
{
c += *it + *bit;
++bit;
}
benchmark::DoNotOptimize(c);
}
}
BENCHMARK(stepper_stepper_ref)->Range(RANGE);
}
}