Remove duplicated performance test

Removing old test that was used to compare with EventBus v1.x
This commit is contained in:
Dawid Drozd 2017-08-06 17:13:53 +02:00
parent ffbf4b91a9
commit fe92d55eb0
3 changed files with 14 additions and 180 deletions

View File

@ -8,7 +8,6 @@ ADD_SUBDIRECTORY(benchmark/)
ADD_EXECUTABLE(EventBusPerformance
eventbus/EventBusPerformance.cpp
eventbus/EventBus2Performance.cpp
${CCNOTIFICATION_CENTER_SRC}
)

View File

@ -1,165 +0,0 @@
//
// Created by Dawid Drozd aka Gelldur on 05.08.17.
//
#include <random>
#include <benchmark/benchmark.h>
#include <eventbus/EventBus.h>
#include <iostream>
namespace
{
void checkNListeners(benchmark::State& state, const int listenersCount)
{
Dexode::EventBus bus;
int sum = 0;
Dexode::Event<int> simpleNotification("simple");
for (int i = 0; i < listenersCount; ++i)
{
bus.listen(simpleNotification, [&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);
});
}
while (state.KeepRunning())//Performance area!
{
bus.notify(simpleNotification, 2);
}
state.counters["sum"] = sum;
}
void checkSimpleNotification_EventBus2(benchmark::State& state)
{
checkNListeners(state, 1);
}
void check10Listeners_EventBus2(benchmark::State& state)
{
checkNListeners(state, 10);
}
void check100Listeners_EventBus2(benchmark::State& state)
{
checkNListeners(state, 100);
}
void check1kListeners_EventBus2(benchmark::State& state)
{
checkNListeners(state, 1000);
}
void call1kLambdas_compare_EventBus2(benchmark::State& state)
{
int sum = 0;
std::vector<std::function<void(int)>> callbacks;
callbacks.reserve(1000);
for (int i = 0; i < 1000; ++i)
{
callbacks.emplace_back([&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);
});
}
while (state.KeepRunning())//Performance area!
{
for (int i = 0; i < 1000; ++i)
// for (auto& callback :callbacks)
{
callbacks[i](2);
}
}
state.counters["sum"] = sum;
}
void checkNNotificationsForNListeners(benchmark::State& state, const int notificationsCount, const int listenersCount)
{
std::mt19937 generator(311281);
std::uniform_int_distribution<int> uniformDistribution(0, notificationsCount - 1);
//We generate here N different notifications
std::vector<Dexode::Event<int>> notifications;
notifications.reserve(notificationsCount);
for (int i = 0; i < notificationsCount; ++i)
{
notifications.emplace_back(std::string{"notify_"} + std::to_string(i));
}
Dexode::EventBus bus;
int sum = 0;
for (int i = 0; i < listenersCount; ++i)//We register M listeners for N notifications using uniform distribution
{
const auto& notification = notifications.at(uniformDistribution(generator));
bus.listen(notification, [&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);//we use it to prevent some? optimizations
});
}
while (state.KeepRunning())//Performance area!
{
//Pick random notification
const auto& notification = notifications.at(uniformDistribution(generator));
bus.notify(notification, uniformDistribution(generator));
}
state.counters["sum"] = sum;
}
void check10NotificationsFor1kListeners_EventBus2(benchmark::State& state)
{
checkNNotificationsForNListeners(state, 10, 1000);
}
void check100NotificationsFor1kListeners_EventBus2(benchmark::State& state)
{
checkNNotificationsForNListeners(state, 100, 1000);
}
void check1kNotificationsFor1kListeners_EventBus2(benchmark::State& state)
{
checkNNotificationsForNListeners(state, 1000, 1000);
}
void check100NotificationsFor10kListeners_EventBus2(benchmark::State& state)
{
checkNNotificationsForNListeners(state, 100, 10000);
}
void checkNotifyFor10kListenersWhenNoOneListens_EventBus2(benchmark::State& state)
{
Dexode::EventBus bus;
Dexode::Event<int> simpleNotification("simple");
Dexode::Event<int> unknownNotification("unknown");
int sum = 0;
for (int i = 0; i < 10000; ++i)
{
bus.listen(simpleNotification, [&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);
});
}
while (state.KeepRunning())//Performance area!
{
bus.notify(unknownNotification, 2);
}
state.counters["sum"] = sum;
}
}
BENCHMARK(call1kLambdas_compare_EventBus2);
BENCHMARK(checkSimpleNotification_EventBus2);
BENCHMARK(check10Listeners_EventBus2);
BENCHMARK(check100Listeners_EventBus2);
BENCHMARK(check1kListeners_EventBus2);
BENCHMARK(check10NotificationsFor1kListeners_EventBus2);
BENCHMARK(check100NotificationsFor1kListeners_EventBus2);
BENCHMARK(check1kNotificationsFor1kListeners_EventBus2);
BENCHMARK(check100NotificationsFor10kListeners_EventBus2);
BENCHMARK(checkNotifyFor10kListenersWhenNoOneListens_EventBus2);

View File

@ -4,20 +4,20 @@
#include <random>
#include <benchmark/benchmark.h>
#include <eventbus/Notifier.h>
#include <eventbus/EventBus.h>
namespace
{
MAKE_NOTIFICATION(SimpleNotification, int);
void checkNListeners(benchmark::State& state, const int listenersCount)
{
Dexode::Notifier bus;
Dexode::EventBus bus;
int sum = 0;
Dexode::Event<int> simple{"simple"};
for (int i = 0; i < listenersCount; ++i)
{
bus.listen(getNotificationSimpleNotification(), [&](int value)
bus.listen(simple, [&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);
});
@ -25,7 +25,7 @@ void checkNListeners(benchmark::State& state, const int listenersCount)
while (state.KeepRunning())//Performance area!
{
bus.notify(getNotificationSimpleNotification(), 2);
bus.notify(simple, 2);
}
state.counters["sum"] = sum;
}
@ -80,14 +80,14 @@ void checkNNotificationsForNListeners(benchmark::State& state, const int notific
std::uniform_int_distribution<int> uniformDistribution(0, notificationsCount - 1);
//We generate here N different notifications
std::vector<Dexode::Notification<int>> notifications;
std::vector<Dexode::Event<int>> notifications;
notifications.reserve(notificationsCount);
for (int i = 0; i < notificationsCount; ++i)
{
notifications.emplace_back(691283);
notifications.emplace_back(std::string{"event_"} + std::to_string(i));
}
Dexode::Notifier bus;
Dexode::EventBus bus;
int sum = 0;
for (int i = 0; i < listenersCount; ++i)//We register M listeners for N notifications using uniform distribution
{
@ -127,15 +127,15 @@ void check100NotificationsFor10kListeners(benchmark::State& state)
checkNNotificationsForNListeners(state, 100, 10000);
}
MAKE_NOTIFICATION(UnknownNotification, int);
void checkNotifyFor10kListenersWhenNoOneListens(benchmark::State& state)
{
Dexode::Notifier bus;
Dexode::EventBus bus;
int sum = 0;
Dexode::Event<int> simple{"simple"};
Dexode::Event<int> unknown{"unknown"};
for (int i = 0; i < 10000; ++i)
{
bus.listen(getNotificationSimpleNotification(), [&](int value)
bus.listen(simple, [&](int value)
{
benchmark::DoNotOptimize(sum += value * 2);
});
@ -143,7 +143,7 @@ void checkNotifyFor10kListenersWhenNoOneListens(benchmark::State& state)
while (state.KeepRunning())//Performance area!
{
bus.notify(getNotificationUnknownNotification(), 2);
bus.notify(unknown, 2);
}
state.counters["sum"] = sum;
}