2
0
mirror of https://github.com/boostorg/hana.git synced 2026-01-31 08:12:16 +00:00
Files
hana/benchmark/transform/execute.std.vector.erb.cpp
Louis Dionne 33f2b4cf2f [Benchmarks] Improve transparency w.r.t Fusion algorithms
Specifically,

(1) We now benchmark with fusion::list too
(2) We now document our methodology for forcing the evaluation of algorithms

Note that we still use `as_list` and `as_vector` to force the evaluation
of algorithms instead of using e.g. `for_each`. This is because we want
to compare apples with apples, and for this we need to get a sequence of
computed values, not only for_each over the view. The disclaimer in the
tutorial saying "Fusion might encourage a different design" takes care
of warning people about the fact that we're not necessarily using
idiomatic Fusion, but not need to benchmark unfairly to try to
account for that.
2015-10-22 18:21:13 -04:00

30 lines
793 B
C++

/*
@copyright Louis Dionne 2015
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#include "measure.hpp"
#include <algorithm>
#include <cstdlib>
#include <vector>
int main () {
boost::hana::benchmark::measure([] {
long long result = 0;
for (int iteration = 0; iteration < 1 << 10; ++iteration) {
std::vector<int> values = {
<%= input_size.times.map { 'std::rand()' }.join(', ') %>
};
std::vector<long long> results;
results.reserve(<%= input_size %>);
std::transform(values.begin(), values.end(), results.begin(), [&](auto t) {
return result += t;
});
}
});
}