Skip to content

Commit a36c30f

Browse files
committed
create benchmarks using 'from_range' and 'from_vector'
1 parent 1409a92 commit a36c30f

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

benchmark/reduce.benchmark.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,41 @@ static void BM_for_loop(benchmark::State& state) {
5252
// std::cout << sum << std::endl;
5353
}
5454

55-
static void BM_sequence(benchmark::State& state) {
55+
static void BM_sequence_from_vector(benchmark::State& state) {
56+
using namespace seq;
57+
std::vector<i64> numbers = random_vector(SAMPLES);
58+
i64 sum = 0;
59+
60+
for (auto _ : state) {
61+
// this code gets timed
62+
auto pipeline = from_vector(numbers,
63+
filter<i64>([](i64 i){ return i%2==0; },
64+
reduce<i64>(std::plus<i64>{}, 0LL,
65+
to_value(sum))));
66+
pipeline.yield(SAMPLES);
67+
}
68+
69+
assert(sum == expected.at(SAMPLES)); // check that the result is correct
70+
}
71+
72+
static void BM_sequence_from_range(benchmark::State& state) {
73+
using namespace seq;
74+
std::vector<i64> numbers = random_vector(SAMPLES);
75+
i64 sum = 0;
76+
77+
for (auto _ : state) {
78+
// this code gets timed
79+
auto pipeline = from_range(numbers.cbegin(), numbers.cend(),
80+
filter<i64>([](i64 i){ return i%2==0; },
81+
reduce<i64>(std::plus<i64>{}, 0LL,
82+
to_value(sum))));
83+
pipeline.yield(SAMPLES);
84+
}
85+
86+
assert(sum == expected.at(SAMPLES)); // check that the result is correct
87+
}
88+
89+
static void BM_sequence_map_hack(benchmark::State& state) {
5690
using namespace seq;
5791
std::vector<i64> numbers = random_vector(SAMPLES);
5892
i64 sum = 0;
@@ -72,4 +106,6 @@ static void BM_sequence(benchmark::State& state) {
72106

73107
// Register the function as a benchmark
74108
BENCHMARK(BM_for_loop);
75-
BENCHMARK(BM_sequence);
109+
BENCHMARK(BM_sequence_from_range);
110+
BENCHMARK(BM_sequence_from_vector);
111+
BENCHMARK(BM_sequence_map_hack);

0 commit comments

Comments
 (0)