forked from Chatterino/chatterino2
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into chatterino7
- Loading branch information
Showing
55 changed files
with
1,699 additions
and
234 deletions.
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
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,28 @@ | ||
project(twitch-eventsub-ws-benchmark) | ||
|
||
set(SOURCES | ||
src/main.cpp | ||
resources/bench.qrc | ||
|
||
src/parse.cpp | ||
) | ||
|
||
add_executable(${PROJECT_NAME} ${SOURCES}) | ||
add_sanitizers(${PROJECT_NAME}) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE | ||
twitch-eventsub-ws | ||
benchmark::benchmark | ||
Qt${MAJOR_QT_VERSION}::Core # for QFile | ||
) | ||
|
||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" | ||
CXX_STANDARD 20 | ||
AUTORCC ON | ||
) | ||
|
||
if(MSVC) | ||
target_compile_options(${PROJECT_NAME} PRIVATE /EHsc /bigobj) | ||
endif() |
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,5 @@ | ||
<RCC> | ||
<qresource prefix="/bench"> | ||
<file>messages.ndjson</file> | ||
</qresource> | ||
</RCC> |
24 changes: 24 additions & 0 deletions
24
lib/twitch-eventsub-ws/benchmarks/resources/messages.ndjson
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
BENCHMARK_MAIN(); |
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,135 @@ | ||
#include "twitch-eventsub-ws/listener.hpp" | ||
#include "twitch-eventsub-ws/session.hpp" | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <boost/beast/core/flat_buffer.hpp> | ||
#include <QFile> | ||
|
||
#include <memory> | ||
|
||
namespace { | ||
|
||
using namespace chatterino::eventsub::lib; | ||
|
||
std::vector<boost::beast::flat_buffer> readMessages() | ||
{ | ||
QFile file(":/bench/messages.ndjson"); | ||
bool ok = file.open(QFile::ReadOnly); | ||
assert(ok); | ||
|
||
std::vector<boost::beast::flat_buffer> messages; | ||
while (!file.atEnd()) | ||
{ | ||
QByteArray line = file.readLine(); | ||
if (line.isEmpty()) | ||
{ | ||
continue; | ||
} | ||
|
||
boost::beast::flat_buffer buf; | ||
auto inner = buf.prepare(line.size()); | ||
std::memcpy(inner.data(), line.data(), inner.size()); | ||
buf.commit(inner.size()); | ||
|
||
messages.emplace_back(std::move(buf)); | ||
} | ||
return messages; | ||
} | ||
|
||
class NoopListener : public Listener | ||
{ | ||
public: | ||
NoopListener() = default; | ||
|
||
// NOLINTBEGIN(cppcoreguidelines-pro-type-const-cast) | ||
void onSessionWelcome( | ||
const messages::Metadata &metadata, | ||
const payload::session_welcome::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onNotification(const messages::Metadata &metadata, | ||
const boost::json::value &jv) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&jv); | ||
} | ||
|
||
void onChannelBan(const messages::Metadata &metadata, | ||
const payload::channel_ban::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onStreamOnline( | ||
const messages::Metadata &metadata, | ||
const payload::stream_online::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onStreamOffline( | ||
const messages::Metadata &metadata, | ||
const payload::stream_offline::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onChannelChatNotification( | ||
const messages::Metadata &metadata, | ||
const payload::channel_chat_notification::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onChannelUpdate( | ||
const messages::Metadata &metadata, | ||
const payload::channel_update::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onChannelChatMessage( | ||
const messages::Metadata &metadata, | ||
const payload::channel_chat_message::v1::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
|
||
void onChannelModerate( | ||
const messages::Metadata &metadata, | ||
const payload::channel_moderate::v2::Payload &payload) override | ||
{ | ||
benchmark::DoNotOptimize(&metadata); | ||
benchmark::DoNotOptimize(&payload); | ||
} | ||
// NOLINTEND(cppcoreguidelines-pro-type-const-cast) | ||
}; | ||
|
||
void BM_ParseAndHandleMessages(benchmark::State &state) | ||
{ | ||
auto messages = readMessages(); | ||
|
||
std::unique_ptr<Listener> listener = std::make_unique<NoopListener>(); | ||
|
||
for (auto _ : state) | ||
{ | ||
for (const auto &msg : messages) | ||
{ | ||
boost::system::error_code ec = handleMessage(listener, msg); | ||
assert(!ec); | ||
} | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
BENCHMARK(BM_ParseAndHandleMessages); |
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
Oops, something went wrong.