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"
|
2024-08-24 12:18:27 +02:00
|
|
|
#include "messages/MessageBuilder.hpp"
|
2024-07-21 15:09:59 +02:00
|
|
|
#include "mocks/BaseApplication.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;
|
|
|
|
|
2024-08-24 12:18:27 +02:00
|
|
|
class BenchmarkMessageBuilder : public MessageBuilder
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit BenchmarkMessageBuilder(
|
|
|
|
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
|
|
|
const MessageParseArgs &_args)
|
2024-08-24 12:18:27 +02:00
|
|
|
: MessageBuilder(_channel, _ircMessage, _args)
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
|
|
|
}
|
2024-08-24 12:18:27 +02:00
|
|
|
|
2022-06-05 17:40:57 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
class MockApplication : public mock::BaseApplication
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
2022-06-06 15:36:53 +02:00
|
|
|
public:
|
2024-07-21 15:09:59 +02:00
|
|
|
MockApplication()
|
|
|
|
: highlights(this->settings, &this->accounts)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:36:53 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
static void BM_HighlightTest(benchmark::State &state)
|
|
|
|
{
|
|
|
|
MockApplication mockApplication;
|
|
|
|
|
|
|
|
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);
|