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

Function Test_example_KeepIf_performance

examples/readme_perf_examples.cpp:60–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60void Test_example_KeepIf_performance()
61{
62 using namespace fplus;
63
64 typedef std::vector<int> Ints;
65 auto run_loop = [&](const Ints values) {
66 Ints odds;
67 for (int x : values)
68 if (is_odd_int(x))
69 odds.push_back(x);
70 return odds;
71 };
72 auto run_stl = [&](const Ints values) {
73 Ints odds;
74 std::copy_if(std::begin(values), std::end(values),
75 std::back_inserter(odds), is_odd_int);
76 return odds;
77 };
78 auto run_FunctionalPlus = [&](const Ints values) { return keep_if(is_odd_int, values); };
79
80 // make debug runs faster
81#if defined NDEBUG || defined _DEBUG
82 std::size_t numRuns = 10;
83#else
84 std::size_t numRuns = 20000;
85#endif
86
87 Ints values = generate<Ints>(rand, 5000);
88 run_n_times(run_loop, numRuns, "Hand-written for loop", values);
89 run_n_times(run_stl, numRuns, "std::copy_if", values);
90 run_n_times(run_FunctionalPlus, numRuns, "FunctionalPlus::keep_if", values);
91}
92
93int main()
94{

Callers 1

mainFunction · 0.85

Calls 3

run_n_timesFunction · 0.85
is_odd_intFunction · 0.70
keep_ifFunction · 0.50

Tested by

no test coverage detected