void benchmark()

in example/comprehensions.cpp [79:129]


void benchmark()
{
    // Define an infinite range containing all the Pythagorean triples:
    auto triples =
        view::for_each(view::ints(1), [](int z)
        {
            return view::for_each(view::ints(1, z+1), [=](int x)
            {
                return view::for_each(view::ints(x, z+1), [=](int y)
                {
                    return yield_if(x*x + y*y == z*z, std::make_tuple(x, y, z));
                });
            });
        });

    static constexpr int max_triples = 3000;

    timer t;
    int result = 0;
    RANGES_FOR(auto triple, triples | view::take(max_triples))
    {
        int i, j, k;
        std::tie(i, j, k) = triple;
        result += (i + j + k);
    }
    std::cout << t << '\n';
    std::cout << result << '\n';

    result = 0;
    int found = 0;
    t.reset();
    for(int z = 1;; ++z)
    {
        for(int x = 1; x <= z; ++x)
        {
            for(int y = x; y <= z; ++y)
            {
                if(x*x + y*y == z*z)
                {
                    result += (x + y + z);
                    ++found;
                    if(found == max_triples)
                        goto done;
                }
            }
        }
    }
done:
    std::cout << t << '\n';
    std::cout << result << '\n';
}