FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/benchmark/benchmark_builder.cpp at master · xtensor-stack/xtensor · GitHub
xtensor-stack
xtensor
Repository navigation
Code
Issues
381
(381)
Pull requests
43
(43)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
xtensor
/
benchmark
/
benchmark_builder.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
221 lines (200 loc) · 7.02 KB
Breadcrumbs
xtensor
/
benchmark
/
benchmark_builder.cpp
Copy path
File metadata and controls
221 lines (200 loc) · 7.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
**************************************************************************
* 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/containers/xtensor.hpp
"
#
include
"
xtensor/core/xnoalias.hpp
"
namespace
xt
{
template
<
class
T
>
inline
auto
builder_xarange
(benchmark::State& state)
{
for
(
auto
_ : state)
{
T res =
xt::arange
(
0
,
10000
);
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
template
<
class
T
>
inline
auto
builder_xarange_manual
(benchmark::State& state)
{
for
(
auto
_ : state)
{
T res =
T::from_shape
({
10000
});
for
(std::
size_t
i =
0
; i <
10000
; ++i)
{
res.
storage
()[i] = i;
}
benchmark::DoNotOptimize
(res.
data
());
}
}
inline
auto
builder_iota_vector
(benchmark::State& state)
{
for
(
auto
_ : state)
{
xt::uvector<
double
> a{};
a.
resize
(
10000
);
std::iota
(a.
begin
(), a.
end
(),
0
);
benchmark::DoNotOptimize
(a.
data
());
}
}
template
<
class
T
>
inline
auto
builder_arange_for_loop_assign
(benchmark::State& state)
{
for
(
auto
_ : state)
{
auto
expr =
xt::arange
(
0
,
10000
);
T res =
T::from_shape
({
10000
});
for
(std::
size_t
i =
0
; i <
10000
; ++i)
{
res
(i) =
expr
(i);
}
benchmark::DoNotOptimize
(res.
data
());
}
}
template
<
class
T
>
inline
auto
builder_arange_for_loop_iter_assign
(benchmark::State& state)
{
for
(
auto
_ : state)
{
auto
expr = xt::arange<
double
>(
0
,
10000
);
T res =
T::from_shape
({
10000
});
auto
xend = expr.
cend
();
auto
reit = res.
begin
();
for
(
auto
it = expr.
cbegin
(); it != xend; ++it)
{
*reit++ = *it;
}
benchmark::DoNotOptimize
(res.
data
());
}
}
template
<
class
T
>
inline
auto
builder_arange_for_loop_iter_assign_backward
(benchmark::State& state)
{
for
(
auto
_ : state)
{
auto
expr = xt::arange<
double
>(
0
,
10000
);
T res =
T::from_shape
({
10000
});
auto
xend = expr.
cend
();
auto
reit = res.
begin
();
auto
it = expr.
cbegin
();
for
(
ptrdiff_t
n =
10000
; n >
0
; --n)
{
*reit = *it;
++it;
++reit;
}
benchmark::DoNotOptimize
(res.
data
());
}
}
template
<
class
T
>
inline
auto
builder_arange_assign_iterator
(benchmark::State& state)
{
for
(
auto
_ : state)
{
auto
xa =
xt::arange
(
0
,
10000
);
T res =
T::from_shape
({
10000
});
std::copy
(xa.
cbegin
(), xa.
cend
(), res.
begin
());
benchmark::DoNotOptimize
(res.
data
());
}
}
template
<
class
T
>
inline
auto
builder_std_iota
(benchmark::State& state)
{
for
(
auto
_ : state)
{
T res =
T::from_shape
({
10000
});
std::iota
(res.
begin
(), res.
end
(),
0
);
benchmark::DoNotOptimize
(res.
data
());
}
}
inline
auto
builder_ones
(benchmark::State& state)
{
for
(
auto
_ : state)
{
xt::xarray<
double
> res = xt::ones<
double
>({
200
,
200
});
benchmark::DoNotOptimize
(res.
data
());
}
}
inline
auto
builder_ones_assign_iterator
(benchmark::State& state)
{
auto
xo = xt::ones<
double
>({
200
,
200
});
for
(
auto
_ : state)
{
xt::xarray<
double
>
res
(xt::dynamic_shape<
size_t
>{
200
,
200
});
auto
xo = xt::ones<
double
>({
200
,
200
});
std::copy
(xo.
begin
(), xo.
end
(), res.
begin
());
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
inline
auto
builder_ones_expr_for
(benchmark::State& state)
{
auto
xo = xt::ones<
double
>({
200
,
200
});
for
(
auto
_ : state)
{
xt::xtensor<
double
,
2
>
res
(xt::static_shape<
size_t
,
2
>({
200
,
200
}));
auto
xo = xt::ones<
double
>({
200
,
200
}) *
0.15
;
for
(std::
size_t
i =
0
; i < xo.
shape
()[
0
]; ++i)
{
for
(std::
size_t
j =
0
; j < xo.
shape
()[
1
]; ++j)
{
res
(i, j) =
xo
(i, j);
}
}
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
inline
auto
builder_ones_expr
(benchmark::State& state)
{
auto
xo = xt::ones<
double
>({
200
,
200
});
for
(
auto
_ : state)
{
xt::xtensor<
double
,
2
> res = xt::ones<
double
>({
200
,
200
}) *
0.15
;
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
inline
auto
builder_ones_expr_fill
(benchmark::State& state)
{
auto
xo = xt::ones<
double
>({
200
,
200
});
for
(
auto
_ : state)
{
xt::xtensor<
double
,
2
> res = xt::xtensor<
double
,
2
>::
from_shape
({
200
,
200
});
std::fill
(res.
begin
(), res.
end
(),
0.15
);
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
inline
auto
builder_std_fill
(benchmark::State& state)
{
for
(
auto
_ : state)
{
xt::xarray<
double
>
res
(xt::dynamic_shape<std::
size_t
>{
200
,
200
});
std::fill
(res.
begin
(), res.
end
(),
1
);
benchmark::DoNotOptimize
(res.
storage
().
data
());
}
}
BENCHMARK_TEMPLATE
(builder_xarange, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_xarange, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_xarange_manual, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_xarange_manual, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_assign, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_assign, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_arange_assign_iterator, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_arange_assign_iterator, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_iter_assign, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_iter_assign_backward, xarray<
double
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_iter_assign, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_arange_for_loop_iter_assign_backward, xtensor<
double
,
1
>);
BENCHMARK_TEMPLATE
(builder_std_iota, xarray<
double
>);
BENCHMARK
(builder_iota_vector);
BENCHMARK
(builder_ones);
BENCHMARK
(builder_ones_assign_iterator);
BENCHMARK
(builder_ones_expr);
BENCHMARK
(builder_ones_expr_fill);
BENCHMARK
(builder_ones_expr_for);
BENCHMARK
(builder_std_fill);
}
Back
|
FazBrowse Home
|
New Git URL