MCPcopy Create free account
hub / github.com/Dobiasd/FunctionalPlus / main

Function main

examples/performance_range_v3.cpp:10–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <range/v3/all.hpp>
9
10int main()
11{
12 const auto times_3 = [](int i) { return 3 * i; };
13 const auto is_odd_int = [](int i) { return i % 2 != 0; };
14 const auto as_string_length = [](int i) { return std::to_string(i).size(); };
15
16 typedef std::chrono::time_point<std::chrono::system_clock> Time;
17
18 for (int i = 0; i < 3; ++i) {
19 // FunctionalPlus
20 Time startTimeFPlus = std::chrono::system_clock::now();
21 using namespace fplus;
22 const auto result_fplus = fwd::apply(
23 numbers(0, 15000000), fwd::transform(times_3), fwd::drop_if(is_odd_int), fwd::transform(as_string_length), fwd::sum());
24 Time endTimeFPlus = std::chrono::system_clock::now();
25 std::chrono::duration<double> elapsed_s_fplus = endTimeFPlus - startTimeFPlus;
26 std::cout << "(check: " << result_fplus << "), elapsed time fplus: " << elapsed_s_fplus.count() << "s\n";
27
28 // range-v3
29 Time startTimeRangev3 = std::chrono::system_clock::now();
30 using namespace ranges;
31 const auto result_range_v3 = accumulate(
32 view::ints(0)
33 | view::take(15000000)
34 | view::transform(times_3)
35 | view::remove_if(is_odd_int)
36 | view::transform(as_string_length),
37 0);
38 Time endTimeRangev3 = std::chrono::system_clock::now();
39 std::chrono::duration<double> elapsed_s_rangev3 = endTimeRangev3 - startTimeRangev3;
40 std::cout << "(check: " << result_range_v3 << "), elapsed time range-v3: " << elapsed_s_rangev3.count() << "s\n";
41 }
42}

Callers

nothing calls this directly

Calls 7

applyFunction · 0.50
numbersFunction · 0.50
transformFunction · 0.50
drop_ifFunction · 0.50
sumFunction · 0.50
accumulateFunction · 0.50
takeFunction · 0.50

Tested by

no test coverage detected