-
-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev: Add RecentMessages benchmark #5071
Changes from all commits
4e3c41d
cf9c48a
472b0f1
3880dc2
d798edb
7622c62
5a3ba1b
c9b3c64
7e7ad76
f21fa08
7413ad3
d66d336
f1cb77f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<RCC> | ||
<qresource prefix="/bench"> | ||
<file>recentmessages-nymn.json</file> | ||
<file>seventvemotes-nymn.json</file> | ||
</qresource> | ||
</RCC> |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,223 @@ | ||||||||||
#include "common/Literals.hpp" | ||||||||||
#include "controllers/accounts/AccountController.hpp" | ||||||||||
#include "controllers/highlights/HighlightController.hpp" | ||||||||||
#include "messages/Emote.hpp" | ||||||||||
#include "mocks/EmptyApplication.hpp" | ||||||||||
#include "mocks/TwitchIrcServer.hpp" | ||||||||||
#include "mocks/UserData.hpp" | ||||||||||
#include "providers/bttv/BttvEmotes.hpp" | ||||||||||
#include "providers/chatterino/ChatterinoBadges.hpp" | ||||||||||
#include "providers/ffz/FfzBadges.hpp" | ||||||||||
#include "providers/ffz/FfzEmotes.hpp" | ||||||||||
#include "providers/recentmessages/Impl.hpp" | ||||||||||
#include "providers/seventv/SeventvBadges.hpp" | ||||||||||
#include "providers/seventv/SeventvEmotes.hpp" | ||||||||||
#include "providers/twitch/TwitchChannel.hpp" | ||||||||||
#include "singletons/Emotes.hpp" | ||||||||||
#include "singletons/Resources.hpp" | ||||||||||
|
||||||||||
#include <benchmark/benchmark.h> | ||||||||||
#include <QFile> | ||||||||||
#include <QJsonArray> | ||||||||||
#include <QJsonDocument> | ||||||||||
#include <QString> | ||||||||||
|
||||||||||
#include <optional> | ||||||||||
|
||||||||||
using namespace chatterino; | ||||||||||
using namespace literals; | ||||||||||
|
||||||||||
namespace { | ||||||||||
|
||||||||||
class MockApplication : mock::EmptyApplication | ||||||||||
{ | ||||||||||
public: | ||||||||||
IEmotes *getEmotes() override | ||||||||||
{ | ||||||||||
return &this->emotes; | ||||||||||
} | ||||||||||
|
||||||||||
IUserDataController *getUserData() override | ||||||||||
{ | ||||||||||
return &this->userData; | ||||||||||
} | ||||||||||
|
||||||||||
AccountController *getAccounts() override | ||||||||||
{ | ||||||||||
return &this->accounts; | ||||||||||
} | ||||||||||
|
||||||||||
ITwitchIrcServer *getTwitch() override | ||||||||||
{ | ||||||||||
return &this->twitch; | ||||||||||
} | ||||||||||
|
||||||||||
ChatterinoBadges *getChatterinoBadges() override | ||||||||||
{ | ||||||||||
return &this->chatterinoBadges; | ||||||||||
} | ||||||||||
|
||||||||||
FfzBadges *getFfzBadges() override | ||||||||||
{ | ||||||||||
return &this->ffzBadges; | ||||||||||
} | ||||||||||
|
||||||||||
SeventvBadges *getSeventvBadges() override | ||||||||||
{ | ||||||||||
return &this->seventvBadges; | ||||||||||
} | ||||||||||
|
||||||||||
HighlightController *getHighlights() override | ||||||||||
{ | ||||||||||
return &this->highlights; | ||||||||||
} | ||||||||||
|
||||||||||
AccountController accounts; | ||||||||||
Emotes emotes; | ||||||||||
mock::UserDataController userData; | ||||||||||
mock::MockTwitchIrcServer twitch; | ||||||||||
ChatterinoBadges chatterinoBadges; | ||||||||||
FfzBadges ffzBadges; | ||||||||||
SeventvBadges seventvBadges; | ||||||||||
HighlightController highlights; | ||||||||||
}; | ||||||||||
|
||||||||||
std::optional<QJsonDocument> tryReadJsonFile(const QString &path) | ||||||||||
{ | ||||||||||
QFile file(path); | ||||||||||
if (!file.open(QFile::ReadOnly)) | ||||||||||
{ | ||||||||||
return std::nullopt; | ||||||||||
} | ||||||||||
|
||||||||||
QJsonParseError e; | ||||||||||
Nerixyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
auto doc = QJsonDocument::fromJson(file.readAll(), &e); | ||||||||||
if (e.error != QJsonParseError::NoError) | ||||||||||
{ | ||||||||||
return std::nullopt; | ||||||||||
} | ||||||||||
|
||||||||||
return doc; | ||||||||||
} | ||||||||||
|
||||||||||
QJsonDocument readJsonFile(const QString &path) | ||||||||||
{ | ||||||||||
auto opt = tryReadJsonFile(path); | ||||||||||
if (!opt) | ||||||||||
{ | ||||||||||
_exit(1); | ||||||||||
} | ||||||||||
return *opt; | ||||||||||
} | ||||||||||
|
||||||||||
class RecentMessages | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'RecentMessages' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] class RecentMessages
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: destructor of 'RecentMessages' is public and non-virtual [cppcoreguidelines-virtual-class-destructor] class RecentMessages
^ Additional contextbenchmarks/src/RecentMessages.cpp:112: make it public and virtual class RecentMessages
^ |
||||||||||
{ | ||||||||||
public: | ||||||||||
explicit RecentMessages(const QString &name_) | ||||||||||
: name(name_) | ||||||||||
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: pass by value and use std::move [modernize-pass-by-value] benchmarks/src/RecentMessages.cpp:25: + #include <utility>
Suggested change
|
||||||||||
, chan(this->name) | ||||||||||
{ | ||||||||||
const auto seventvEmotes = | ||||||||||
tryReadJsonFile(u":/bench/seventvemotes-%1.json"_s.arg(this->name)); | ||||||||||
const auto bttvEmotes = | ||||||||||
tryReadJsonFile(u":/bench/bttvemotes-%1.json"_s.arg(this->name)); | ||||||||||
const auto ffzEmotes = | ||||||||||
tryReadJsonFile(u":/bench/ffzemotes-%1.json"_s.arg(this->name)); | ||||||||||
|
||||||||||
if (seventvEmotes) | ||||||||||
{ | ||||||||||
this->chan.setSeventvEmotes( | ||||||||||
std::make_shared<const EmoteMap>(seventv::detail::parseEmotes( | ||||||||||
seventvEmotes->object()["emote_set"_L1] | ||||||||||
.toObject()["emotes"_L1] | ||||||||||
.toArray(), | ||||||||||
false))); | ||||||||||
} | ||||||||||
|
||||||||||
if (bttvEmotes) | ||||||||||
{ | ||||||||||
this->chan.setBttvEmotes(std::make_shared<const EmoteMap>( | ||||||||||
bttv::detail::parseChannelEmotes(bttvEmotes->object(), | ||||||||||
this->name))); | ||||||||||
} | ||||||||||
|
||||||||||
if (ffzEmotes) | ||||||||||
{ | ||||||||||
this->chan.setFfzEmotes(std::make_shared<const EmoteMap>( | ||||||||||
ffz::detail::parseChannelEmotes(ffzEmotes->object()))); | ||||||||||
} | ||||||||||
|
||||||||||
this->messages = | ||||||||||
readJsonFile(u":/bench/recentmessages-%1.json"_s.arg(this->name)); | ||||||||||
} | ||||||||||
|
||||||||||
~RecentMessages() | ||||||||||
{ | ||||||||||
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); | ||||||||||
} | ||||||||||
|
||||||||||
virtual void run(benchmark::State &state) = 0; | ||||||||||
|
||||||||||
protected: | ||||||||||
QString name; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for protected member 'name' [readability-identifier-naming] benchmarks/src/RecentMessages.cpp:116: - : name(name_)
- , chan(this->name)
+ : name_(name_)
+ , chan(this->name_) benchmarks/src/RecentMessages.cpp:120: - tryReadJsonFile(u":/bench/seventvemotes-%1.json"_s.arg(this->name));
+ tryReadJsonFile(u":/bench/seventvemotes-%1.json"_s.arg(this->name_)); benchmarks/src/RecentMessages.cpp:122: - tryReadJsonFile(u":/bench/bttvemotes-%1.json"_s.arg(this->name));
+ tryReadJsonFile(u":/bench/bttvemotes-%1.json"_s.arg(this->name_)); benchmarks/src/RecentMessages.cpp:124: - tryReadJsonFile(u":/bench/ffzemotes-%1.json"_s.arg(this->name));
+ tryReadJsonFile(u":/bench/ffzemotes-%1.json"_s.arg(this->name_)); benchmarks/src/RecentMessages.cpp:140: - this->name)));
+ this->name_))); benchmarks/src/RecentMessages.cpp:150: - readJsonFile(u":/bench/recentmessages-%1.json"_s.arg(this->name));
+ readJsonFile(u":/bench/recentmessages-%1.json"_s.arg(this->name_));
Suggested change
|
||||||||||
MockApplication app; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for protected member 'app' [readability-identifier-naming]
Suggested change
|
||||||||||
TwitchChannel chan; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for protected member 'chan' [readability-identifier-naming] benchmarks/src/RecentMessages.cpp:117: - , chan(this->name)
+ , chan_(this->name) benchmarks/src/RecentMessages.cpp:128: - this->chan.setSeventvEmotes(
+ this->chan_.setSeventvEmotes( benchmarks/src/RecentMessages.cpp:138: - this->chan.setBttvEmotes(std::make_shared<const EmoteMap>(
+ this->chan_.setBttvEmotes(std::make_shared<const EmoteMap>( benchmarks/src/RecentMessages.cpp:145: - this->chan.setFfzEmotes(std::make_shared<const EmoteMap>(
+ this->chan_.setFfzEmotes(std::make_shared<const EmoteMap>(
Suggested change
benchmarks/src/RecentMessages.cpp:201: - parsed, &this->chan);
+ parsed, &this->chan_); |
||||||||||
QJsonDocument messages; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for protected member 'messages' [readability-identifier-naming] benchmarks/src/RecentMessages.cpp:149: - this->messages =
+ this->messages_ =
Suggested change
benchmarks/src/RecentMessages.cpp:180: - this->messages.object());
+ this->messages_.object()); benchmarks/src/RecentMessages.cpp:197: - this->messages.object());
+ this->messages_.object()); |
||||||||||
}; | ||||||||||
|
||||||||||
class ParseRecentMessages : public RecentMessages | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: destructor of 'ParseRecentMessages' is public and non-virtual [cppcoreguidelines-virtual-class-destructor] class ParseRecentMessages : public RecentMessages
^ Additional contextbenchmarks/src/RecentMessages.cpp:167: make it public and virtual class ParseRecentMessages : public RecentMessages
^ |
||||||||||
{ | ||||||||||
public: | ||||||||||
explicit ParseRecentMessages(const QString &name_) | ||||||||||
: RecentMessages(name_) | ||||||||||
{ | ||||||||||
} | ||||||||||
|
||||||||||
void run(benchmark::State &state) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions]
Suggested change
|
||||||||||
{ | ||||||||||
for (auto _ : state) | ||||||||||
{ | ||||||||||
auto parsed = recentmessages::detail::parseRecentMessages( | ||||||||||
this->messages.object()); | ||||||||||
benchmark::DoNotOptimize(parsed); | ||||||||||
} | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
class BuildRecentMessages : public RecentMessages | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: destructor of 'BuildRecentMessages' is public and non-virtual [cppcoreguidelines-virtual-class-destructor] class BuildRecentMessages : public RecentMessages
^ Additional contextbenchmarks/src/RecentMessages.cpp:186: make it public and virtual class BuildRecentMessages : public RecentMessages
^ |
||||||||||
{ | ||||||||||
public: | ||||||||||
explicit BuildRecentMessages(const QString &name_) | ||||||||||
: RecentMessages(name_) | ||||||||||
{ | ||||||||||
} | ||||||||||
|
||||||||||
void run(benchmark::State &state) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions]
Suggested change
|
||||||||||
{ | ||||||||||
auto parsed = recentmessages::detail::parseRecentMessages( | ||||||||||
this->messages.object()); | ||||||||||
for (auto _ : state) | ||||||||||
{ | ||||||||||
auto built = recentmessages::detail::buildRecentMessages( | ||||||||||
parsed, &this->chan); | ||||||||||
benchmark::DoNotOptimize(built); | ||||||||||
} | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
void BM_ParseRecentMessages(benchmark::State &state, const QString &name) | ||||||||||
{ | ||||||||||
ParseRecentMessages bench(name); | ||||||||||
bench.run(state); | ||||||||||
} | ||||||||||
|
||||||||||
void BM_BuildRecentMessages(benchmark::State &state, const QString &name) | ||||||||||
{ | ||||||||||
BuildRecentMessages bench(name); | ||||||||||
bench.run(state); | ||||||||||
} | ||||||||||
|
||||||||||
} // namespace | ||||||||||
|
||||||||||
BENCHMARK_CAPTURE(BM_ParseRecentMessages, nymn, u"nymn"_s); | ||||||||||
BENCHMARK_CAPTURE(BM_BuildRecentMessages, nymn, u"nymn"_s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'BM_EmojiParsing2' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]