FTXUI/src/ftxui/dom/benchmark_test.cpp
2024-08-16 11:19:51 +02:00

87 lines
2.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <benchmark/benchmark.h>
#include "ftxui/dom/elements.hpp" // for gauge, separator, operator|, text, Element, hbox, vbox, blink, border, inverted
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui {
static void BencharkBasic(benchmark::State& state) {
while (state.KeepRunning()) {
auto document = vbox({
text("Test"),
separator(),
hbox({
gauge(0.9f),
separator() | blink,
gauge(0.5f),
separator() | inverted,
gauge(0.1f),
separator(),
}),
text("Test"),
}) |
border;
auto root = gauge(1.0);
Screen screen(80, state.range(0));
Render(screen, root);
screen.ToString();
}
}
BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16);
static void BencharkText(benchmark::State& state) {
while (state.KeepRunning()) {
std::string content = " world ";
for (int i = 0; i < state.range(0); ++i) {
content += content;
}
auto document = paragraph(content);
Screen screen(200, 200);
Render(screen, document);
screen.ToString();
}
}
BENCHMARK(BencharkText)->DenseRange(0, 10, 1);
static void BenchmarkStyle(benchmark::State& state) {
while (state.KeepRunning()) {
Elements elements;
for (int i = 0; i < state.range(0); ++i) {
elements.push_back(vbox({
text("Test") | bold,
text("Test") | dim,
text("Test") | inverted,
text("Test") | underlined,
text("Test") | underlinedDouble,
text("Test") | strikethrough,
text("Test") | color(Color::Red),
text("Test") | bgcolor(Color::Red),
text("Test") | color(Color::RGB(42, 87, 124)),
text("Test") | bgcolor(Color::RGB(42, 87, 124)),
text("Test") | color(Color::RGB(42, 87, 124)) |
bgcolor(Color::RGB(172, 94, 212)),
text("Test") | blink,
text("Test") | automerge,
}));
elements.push_back(separator());
}
auto document = hbox(std::move(elements));
Screen screen(state.range(1), state.range(1));
Render(screen, document);
screen.ToString();
}
}
BENCHMARK(BenchmarkStyle)
->ArgsProduct({
benchmark::CreateDenseRange(1, 10, 3), // Number of elements.
benchmark::CreateDenseRange(10, 200, 20), // Screen width.
});
} // namespace ftxui
// NOLINTEND