@@ -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
74108BENCHMARK (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