Skip to content

Commit

Permalink
add new benchmarks (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
victimsnino authored Jul 28, 2022
1 parent 31622ef commit c6e60d7
Show file tree
Hide file tree
Showing 2 changed files with 325 additions and 41 deletions.
182 changes: 161 additions & 21 deletions src/tests/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ TEST_CASE("Observable subscribe #2")
};
}


TEST_CASE("Observer construction")
{
BENCHMARK("Specific observer construction")
Expand Down Expand Up @@ -198,26 +197,6 @@ TEST_CASE("Observable lift")
validate_observable(MakeDynamicObservable(), "Dynamic");
}

TEST_CASE("Operators")
{
BENCHMARK_ADVANCED("map construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{ [](const int&) {} };

meter.measure([&]
{
return obs.map([](const auto& v)
{
return v * 100;
}).subscribe(sub);
});
};
}

TEST_CASE("Subscription")
{
BENCHMARK("composite_subscription create")
Expand Down Expand Up @@ -265,6 +244,140 @@ TEST_CASE("foundamental sources")
};
}

TEST_CASE("map")
{
BENCHMARK_ADVANCED("map construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{[](const int&) {}};

meter.measure([&]
{
return obs.map([](const auto& v)
{
return v * 100;
}).subscribe(sub);
});
};
}

TEST_CASE("scan")
{
BENCHMARK_ADVANCED("scan construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{[](const std::vector<int>&) {}};

meter.measure([&]
{
return obs.scan(std::vector<int>{},
[](std::vector<int>&& seed, const auto& v)
{
return std::move(seed);
}).subscribe(sub);
});
};
}

TEST_CASE("distinct_until_changed")
{
BENCHMARK_ADVANCED("distinct_until_changed construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
sub.on_next(1);
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{[](const int&) {}};

meter.measure([&]
{
return obs.distinct_until_changed().subscribe(sub);
});
};
}

TEST_CASE("with_latest_from")
{
BENCHMARK_ADVANCED("with_latest_from construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{[](const std::tuple<int,int,int>&) {}};

meter.measure([&]
{
return obs.with_latest_from(obs, obs).subscribe(sub);
});
};
}

TEST_CASE("switch_on_next")
{
BENCHMARK_ADVANCED("switch_on_next construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
auto inner_source = rpp::source::just(1);
using inner_source_type = decltype(inner_source);
const auto obs = rpp::observable::create<inner_source_type>([&](const auto& sub)
{
sub.on_next(inner_source);
sub.on_next(inner_source);
sub.on_next(inner_source);
});
auto sub = rpp::specific_subscriber{[](const int&) {}};

meter.measure([&]
{
return obs.switch_on_next().subscribe(sub);
});
};
}

TEST_CASE("observe_on")
{
BENCHMARK_ADVANCED("observe_on construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
sub.on_next(1);
sub.on_next(1);
});
auto sub = rpp::specific_subscriber{[](const int&) {}};
auto scheduler = rpp::schedulers::immediate{};
meter.measure([&]
{
return obs.observe_on(scheduler).subscribe(sub);
});
};
}

TEST_CASE("repeat")
{
BENCHMARK_ADVANCED("repeat construction from observable via dot + subscribe")(Catch::Benchmark::Chronometer meter)
{
const auto obs = rpp::observable::create<int>([](const auto& sub)
{
sub.on_next(1);
sub.on_completed();
});
auto sub = rpp::specific_subscriber{[](const int&) {}};

meter.measure([&]
{
return obs.repeat(10).subscribe(sub);
});
};
}

TEST_CASE("just")
{
Expand Down Expand Up @@ -321,6 +434,33 @@ TEST_CASE("merge")
};
}

TEST_CASE("concat")
{
BENCHMARK_ADVANCED("concat")(Catch::Benchmark::Chronometer meter)
{
auto sub = rpp::make_specific_subscriber<int>();

meter.measure([&]
{
return rpp::source::just(rpp::source::just(1),
rpp::source::just(2))
.concat()
.subscribe(sub);
});
};
BENCHMARK_ADVANCED("concat_with")(Catch::Benchmark::Chronometer meter)
{
auto sub = rpp::make_specific_subscriber<int>();

meter.measure([&]
{
return rpp::source::just(1)
.concat_with(rpp::source::just(2))
.subscribe(sub);
});
};
}

TEST_CASE("publish_subject callbacks")
{
BENCHMARK_ADVANCED("on_next")(Catch::Benchmark::Chronometer meter)
Expand Down
Loading

1 comment on commit c6e60d7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux CLANG

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 0.29ns 0.402456 0.71 0.58ns
Dynamic observable construction 22.74ns 29.104 0.78 18.10ns
Specific observable construction + as_dynamic 20.43ns 28.8217 0.71 18.12ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 55.65ns 78.7922 0.71 206.97ns
Specific observable lift dynamic observer 75.21ns 110.797 0.68 215.56ns
Dynamic observable lift specific observer 114.44ns 160.895 0.71 238.84ns
Dynamic observable lift dynamic observer 126.48ns 177.013 0.71 234.76ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 34.76ns 48.5971 0.72 203.96ns
Specific observable subscribe dynamic observer 43.76ns 61.6981 0.71 207.91ns
Dynamic observable subscribe specific observer 79.41ns 111.121 0.71 235.94ns
Dynamic observable subscribe dynamic observer 82.33ns 116.012 0.71 225.89ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 36.75ns 48.7619 0.75 202.00ns
Dynamic observable subscribe lambda 80.91ns 110.874 0.73 231.95ns
Specific observable subscribe lambda without subscription 36.76ns 48.7006 0.75 201.20ns
Dynamic observable subscribe lambda without subscription 81.30ns 110.816 0.73 235.99ns
Specific observable subscribe specific subscriber 11.49ns 16.1249 0.71 151.82ns
Dynamic observable subscribe specific subscriber 55.05ns 77.5541 0.71 185.88ns
Specific observable subscribe dynamic observer 11.50ns 16.0986 0.71 161.85ns
Dynamic observable subscribe dynamic observer 48.44ns 68.4398 0.71 178.90ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 0.29ns 0.402698 0.71 0.29ns
Dynamic observer construction 22.38ns 28.5935 0.78 14.10ns
Specific observer construction + as_dynamic 21.68ns 28.6441 0.76 14.04ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.32ns 0.442799 0.71 0.57ns
Dynamic observer OnNext 1.43ns 1.60606 0.89 1.44ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 24.04ns 32.95 0.73 48.04ns
Make copy of subscriber 11.46ns 16.0463 0.71 3.60ns
Transform subsriber to dynamic 33.59ns 47.3405 0.71 17.98ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 25.30ns 33.2063 0.76 35.10ns
composite_subscription add 32.69ns 48.5511 0.67 16.02ns
composite_subscription unsubscribe 5.74ns 8.03928 0.71 7.74ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 12.00ns None . 91.15ns
concat_with 54.83ns None . 209.50ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 84.25ns None . 173.15ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 11.50ns 16.0624 0.72 22.83ns
error 34.79ns 48.7614 0.71 52.68ns
never 11.50ns 16.0635 0.72 159.62ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 18.67ns 26.2508 0.71 36.40ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 11.50ns 16.0964 0.71 23.54ns
just send variadic 13.54ns 18.9144 0.72 27.98ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 54.24ns 75.8481 0.72 187.00ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 12.05ns 16.7587 0.72 90.15ns
merge_with 55.08ns 76.7206 0.72 211.58ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 551.04ns None . 1730.43ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 21.16ns 29.6464 0.71 6.62ns
on_error 1.45ns 2.01887 0.72 13.60ns
on_completed 1.44ns 1.67005 0.86 0.43ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 119.83ns 165.492 0.72 115.40ns
get_observable 24.06ns 33.7732 0.71 34.36ns
get_subscriber 48.17ns 67.149 0.72 8.48ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 35.99ns None . 9.54ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 81.75ns None . 212.81ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 1197.18ns None . 2260.12ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 492.17ns None . 791.38ns

Linux GCC

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 0.39ns 0.335243 1.16 0.40ns
Dynamic observable construction 37.42ns 19.0616 1.96 28.34ns
Specific observable construction + as_dynamic 37.57ns 18.5425 2.03 27.35ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 92.24ns 27.1551 3.40 413.10ns
Specific observable lift dynamic observer 139.39ns 30.6089 4.55 447.90ns
Dynamic observable lift specific observer 194.84ns 74.4007 2.62 456.86ns
Dynamic observable lift dynamic observer 216.35ns 67.6139 3.20 457.41ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 56.71ns 23.0778 2.46 395.29ns
Specific observable subscribe dynamic observer 72.94ns 24.5418 2.97 406.33ns
Dynamic observable subscribe specific observer 146.25ns 51.3153 2.85 457.10ns
Dynamic observable subscribe dynamic observer 145.02ns 39.2512 3.69 427.08ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 58.31ns 24.6899 2.36 402.44ns
Dynamic observable subscribe lambda 140.98ns 52.5253 2.68 466.99ns
Specific observable subscribe lambda without subscription 58.40ns 23.3879 2.50 405.88ns
Dynamic observable subscribe lambda without subscription 146.08ns 58.3123 2.51 453.58ns
Specific observable subscribe specific subscriber 20.08ns 3.61953 5.55 333.43ns
Dynamic observable subscribe specific subscriber 101.07ns 30.8692 3.27 391.68ns
Specific observable subscribe dynamic observer 20.12ns 3.62093 5.56 343.13ns
Dynamic observable subscribe dynamic observer 81.62ns 15.2874 5.34 363.35ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 0.40ns 0.335119 1.20 0.40ns
Dynamic observer construction 37.81ns 19.4248 1.95 25.13ns
Specific observer construction + as_dynamic 38.05ns 19.643 1.94 25.22ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.40ns 0.335213 1.20 0.40ns
Dynamic observer OnNext 2.41ns 2.01266 1.20 2.41ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 47.97ns 21.757 2.20 70.81ns
Make copy of subscriber 20.10ns 4.17552 4.81 5.39ns
Transform subsriber to dynamic 54.32ns 21.7343 2.50 31.49ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 36.46ns 20.9425 1.74 69.45ns
composite_subscription add 52.67ns 22.0532 2.39 21.12ns
composite_subscription unsubscribe 7.79ns 8.35701 0.93 13.07ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 20.93ns None . 175.17ns
concat_with 104.48ns None . 411.55ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 152.62ns None . 422.90ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 19.12ns 3.4968 5.47 55.93ns
error 57.28ns 35.8609 1.60 96.21ns
never 20.09ns 3.58086 5.61 335.03ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 36.94ns 22.6251 1.63 81.80ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 20.11ns 3.65151 5.51 60.42ns
just send variadic 20.15ns 4.08065 4.94 64.44ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 87.28ns 14.906 5.86 421.09ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 20.72ns 3.93679 5.26 176.28ns
merge_with 104.78ns 42.966 2.44 414.85ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 920.59ns None . 3333.64ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 28.91ns 17.0707 1.69 12.41ns
on_error 1.21ns 1.01276 1.20 20.21ns
on_completed 0.79ns 1.34519 0.59 1.21ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 207.69ns 118.262 1.76 207.18ns
get_observable 38.38ns 5.24576 7.32 54.77ns
get_subscriber 73.52ns 12.3452 5.96 24.27ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 62.34ns None . 26.84ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 139.77ns None . 480.56ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 2004.10ns None . 5254.43ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 853.99ns None . 1667.78ns

Windows MSVC

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 2.14ns 1.96587 1.09 0.42ns
Dynamic observable construction 68.27ns 79.4871 0.86 118.53ns
Specific observable construction + as_dynamic 68.40ns 74.0749 0.92 118.30ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 137.76ns 132.076 1.04 1182.29ns
Specific observable lift dynamic observer 170.44ns 168.187 1.01 1234.19ns
Dynamic observable lift specific observer 251.08ns 274.2 0.92 1360.00ns
Dynamic observable lift dynamic observer 228.36ns 280.139 0.82 1265.60ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 93.90ns 143.275 0.66 1142.41ns
Specific observable subscribe dynamic observer 110.96ns 132.926 0.83 1168.48ns
Dynamic observable subscribe specific observer 198.64ns 203.144 0.98 1319.74ns
Dynamic observable subscribe dynamic observer 167.16ns 204.46 0.82 1202.71ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 95.07ns 140.293 0.68 1148.68ns
Dynamic observable subscribe lambda 204.30ns 232.283 0.88 1319.16ns
Specific observable subscribe lambda without subscription 94.96ns 104.071 0.91 1141.45ns
Dynamic observable subscribe lambda without subscription 204.50ns 224.524 0.91 1316.21ns
Specific observable subscribe specific subscriber 16.07ns 18.4897 0.87 841.60ns
Dynamic observable subscribe specific subscriber 122.76ns 126.317 0.97 1023.16ns
Specific observable subscribe dynamic observer 16.15ns 15.5373 1.04 919.18ns
Dynamic observable subscribe dynamic observer 68.10ns 98.4744 0.69 942.07ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 0.42ns 0.598628 0.70 2.01ns
Dynamic observer construction 69.12ns 91.53 0.76 109.54ns
Specific observer construction + as_dynamic 68.42ns 81.8881 0.84 109.56ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.81ns 0.81364 0.99 0.45ns
Dynamic observer OnNext 1.65ns 1.77067 0.93 2.01ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 75.14ns 102.745 0.73 319.34ns
Make copy of subscriber 16.08ns 14.1538 1.14 37.49ns
Transform subsriber to dynamic 89.61ns 104.707 0.86 146.49ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 76.26ns 105.813 0.72 311.90ns
composite_subscription add 65.08ns 82.4133 0.79 64.60ns
composite_subscription unsubscribe 8.07ns 6.51231 1.24 23.91ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 41.18ns None . 641.49ns
concat_with 291.81ns None . 1413.69ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 169.77ns None . 1024.44ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 16.21ns 17.3457 0.93 188.75ns
error 51.94ns 47.4717 1.09 236.02ns
never 16.24ns 20.1439 0.81 835.03ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 74.36ns 96.3911 0.77 253.61ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 23.56ns 23.1176 1.02 186.97ns
just send variadic 24.37ns 22.2048 1.10 193.55ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 88.70ns 208.201 0.43 989.80ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 41.34ns 39.8292 1.04 655.02ns
merge_with 292.76ns 351.583 0.83 1414.81ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 969.80ns None . 5551.80ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 22.72ns 22.3176 1.02 29.03ns
on_error 2.28ns 2.54124 0.90 22.93ns
on_completed 2.04ns 2.84251 0.72 0.82ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 285.34ns 359.315 0.79 607.00ns
get_observable 31.08ns 26.4311 1.18 151.47ns
get_subscriber 61.86ns 56.3149 1.10 100.75ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 107.87ns None . 108.13ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 163.71ns None . 1253.90ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 2606.00ns None . 12016.50ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 1026.32ns None . 3917.00ns

Please sign in to comment.