-
-
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4e3c41d
dev: add recentmessages benchmark
Nerixyz cf9c48a
chore: add changelog entry
Nerixyz 472b0f1
fix: pch
Nerixyz 3880dc2
fix: star
Nerixyz d798edb
fix: slow pc
Nerixyz 7622c62
fix: it has to be app
Nerixyz 5a3ba1b
fix: suggestions
Nerixyz c9b3c64
Merge remote-tracking branch 'upstream/master' into dev/recentmessage…
Nerixyz 7e7ad76
fix: use the setters
Nerixyz f21fa08
nit: typo
pajlada 7413ad3
unrelated: don't do args tuple magic in other benchmarks
pajlada d66d336
make our own fixture magic & call initresources in main
pajlada f1cb77f
split build & parse
pajlada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,181 @@ | ||||||
#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 BM_RecentMessages | ||||||
{ | ||||||
public: | ||||||
explicit BM_RecentMessages(const QString &name_) | ||||||
: name(name_) | ||||||
, 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)); | ||||||
} | ||||||
|
||||||
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()); | ||||||
auto built = recentmessages::detail::buildRecentMessages( | ||||||
parsed, &this->chan); | ||||||
benchmark::DoNotOptimize(built); | ||||||
} | ||||||
} | ||||||
|
||||||
protected: | ||||||
QString name; | ||||||
MockApplication app; | ||||||
TwitchChannel chan; | ||||||
QJsonDocument messages; | ||||||
}; | ||||||
|
||||||
void BM_BuildRecentMessages(benchmark::State &state, const QString &name) | ||||||
{ | ||||||
BM_RecentMessages bench(name); | ||||||
bench.run(state); | ||||||
} | ||||||
|
||||||
} // namespace | ||||||
|
||||||
BENCHMARK_CAPTURE(BM_BuildRecentMessages, nymn, u"nymn"_s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]