MCPcopy Create free account
hub / github.com/ashvardanian/less_slow.cpp / pipeline_cpp20_std_ranges

Function pipeline_cpp20_std_ranges

less_slow.cpp:3953–3973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3951}
3952
3953static void pipeline_cpp20_std_ranges(bm::State &state) {
3954 std::uint64_t sum = 0, count = 0;
3955 for (auto _ : state) {
3956 auto pipeline = //
3957 std::views::iota(pipe_start, pipe_end + 1) | //
3958 std::views::filter(not_fn(is_power_of_two)) | //
3959 std::views::filter(not_fn(is_power_of_three)) | //
3960 std::views::transform([](std::uint64_t x) { return prime_factors_view(x); }) | //
3961 std::views::join;
3962
3963 // Interestingly, STL still struggles with non-homogeneous ranges,
3964 // if the `begin` and `end` iterators are of different types:
3965 //
3966 // std::uint64_t sum = std::accumulate(
3967 // pipeline.begin(), pipeline.end(), std::uint64_t{0});
3968 //
3969 sum = 0, count = 0;
3970 for (std::uint64_t factor : pipeline) sum += factor, count++;
3971 if (count != 84 || sum != 645) state.SkipWithError("Incorrect result");
3972 }
3973}
3974
3975BENCHMARK(pipeline_cpp20_std_ranges);
3976#endif // defined(__cpp_lib_ranges)

Callers

nothing calls this directly

Calls 2

not_fnFunction · 0.85
prime_factors_viewClass · 0.85

Tested by

no test coverage detected