2022-06-05 17:40:57 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "common/Channel.hpp"
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2022-06-09 16:37:52 +02:00
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
2022-06-05 17:40:57 +02:00
|
|
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "messages/SharedMessageBuilder.hpp"
|
2023-05-20 12:54:50 +02:00
|
|
|
#include "mocks/EmptyApplication.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2022-06-05 17:40:57 +02:00
|
|
|
#include "util/Helpers.hpp"
|
|
|
|
|
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QString>
|
2023-05-26 14:54:23 +02:00
|
|
|
#include <QTemporaryDir>
|
2022-06-05 17:40:57 +02:00
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
class BenchmarkMessageBuilder : public SharedMessageBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit BenchmarkMessageBuilder(
|
|
|
|
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
|
|
|
const MessageParseArgs &_args)
|
|
|
|
: SharedMessageBuilder(_channel, _ircMessage, _args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual MessagePtr build()
|
|
|
|
{
|
|
|
|
// PARSE
|
|
|
|
this->parse();
|
|
|
|
this->usernameColor_ = getRandomColor(this->ircMessage->nick());
|
|
|
|
|
|
|
|
// words
|
|
|
|
// this->addWords(this->originalMessage_.split(' '));
|
|
|
|
|
|
|
|
this->message().messageText = this->originalMessage_;
|
|
|
|
this->message().searchText = this->message().localizedName + " " +
|
|
|
|
this->userName + ": " +
|
|
|
|
this->originalMessage_;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bench()
|
|
|
|
{
|
|
|
|
this->parseHighlights();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-20 12:54:50 +02:00
|
|
|
class MockApplication : mock::EmptyApplication
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
2022-06-06 15:36:53 +02:00
|
|
|
public:
|
|
|
|
AccountController *getAccounts() override
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
|
|
|
return &this->accounts;
|
|
|
|
}
|
2022-06-09 16:37:52 +02:00
|
|
|
HighlightController *getHighlights() override
|
|
|
|
{
|
|
|
|
return &this->highlights;
|
|
|
|
}
|
2022-06-05 17:40:57 +02:00
|
|
|
|
|
|
|
AccountController accounts;
|
2022-06-09 16:37:52 +02:00
|
|
|
HighlightController highlights;
|
2022-06-05 17:40:57 +02:00
|
|
|
// TODO: Figure this out
|
|
|
|
};
|
|
|
|
|
|
|
|
static void BM_HighlightTest(benchmark::State &state)
|
|
|
|
{
|
|
|
|
MockApplication mockApplication;
|
2023-05-26 14:54:23 +02:00
|
|
|
QTemporaryDir settingsDir;
|
|
|
|
Settings settings(settingsDir.path());
|
2022-06-05 17:40:57 +02:00
|
|
|
|
|
|
|
std::string message =
|
|
|
|
R"(@badge-info=subscriber/34;badges=moderator/1,subscriber/24;color=#FF0000;display-name=테스트계정420;emotes=41:6-13,15-22;flags=;id=a3196c7e-be4c-4b49-9c5a-8b8302b50c2a;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1590922213730;turbo=0;user-id=117166826;user-type=mod :testaccount_420!testaccount_420@testaccount_420.tmi.twitch.tv PRIVMSG #pajlada :-tags Kreygasm,Kreygasm (no space))";
|
|
|
|
auto ircMessage = Communi::IrcMessage::fromData(message.c_str(), nullptr);
|
|
|
|
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
|
|
|
assert(privMsg != nullptr);
|
|
|
|
MessageParseArgs args;
|
|
|
|
auto emptyChannel = Channel::getEmpty();
|
|
|
|
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
state.PauseTiming();
|
|
|
|
BenchmarkMessageBuilder b(emptyChannel.get(), privMsg, args);
|
|
|
|
|
|
|
|
b.build();
|
|
|
|
state.ResumeTiming();
|
|
|
|
|
|
|
|
b.bench();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(BM_HighlightTest);
|