-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacc_vs_partsum.cpp
37 lines (29 loc) · 995 Bytes
/
acc_vs_partsum.cpp
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
// Compare std::accumulate vs std::partial_sum to measure raw read vs. write latency
// Copyright 2019 Jeff Trull <edaskel@att.net>
#include "benchmark_scan.hpp"
#include <iostream>
#include <vector>
#include <numeric>
// introduce Google Benchmark
#include <benchmark/benchmark.h>
int main(int argc, char* argv[])
{
// process and remove gbench arguments
benchmark::Initialize(&argc, argv);
benchmark::RegisterBenchmark(
"std::accumulate",
[](benchmark::State &state)
{
RandomInputFixture<int> inp(state);
for (auto _ : state) {
int result = std::accumulate(inp.data.begin(), inp.data.end(), 0);
benchmark::DoNotOptimize(result);
}
})->Range(8, 1 << 25)->UseRealTime();
register_benchmark(
"std::partial_sum",
partial_sum<
std::vector<int>::const_iterator,
std::vector<int>::iterator>);
benchmark::RunSpecifiedBenchmarks();
}