2023-07-29 02:54:30 +08:00
|
|
|
|
#include <iostream>
|
2021-06-26 06:08:21 +08:00
|
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
|
2022-04-28 16:43:31 +08:00
|
|
|
|
#include "ftxui/dom/elements.hpp" // for gauge, separator, operator|, text, Element, hbox, vbox, blink, border, inverted
|
2022-01-07 18:03:54 +08:00
|
|
|
|
#include "ftxui/dom/node.hpp" // for Render
|
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
2021-06-26 06:08:21 +08:00
|
|
|
|
|
2023-03-27 02:20:02 +08:00
|
|
|
|
// NOLINTBEGIN
|
2022-04-17 21:47:20 +08:00
|
|
|
|
namespace ftxui {
|
2021-06-26 06:08:21 +08:00
|
|
|
|
|
|
|
|
|
static void BencharkBasic(benchmark::State& state) {
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
|
auto document = vbox({
|
2021-08-09 05:25:20 +08:00
|
|
|
|
text("Test"),
|
2021-06-26 06:08:21 +08:00
|
|
|
|
separator(),
|
|
|
|
|
hbox({
|
2023-03-27 02:20:02 +08:00
|
|
|
|
gauge(0.9f),
|
2021-06-26 06:08:21 +08:00
|
|
|
|
separator() | blink,
|
2023-03-27 02:20:02 +08:00
|
|
|
|
gauge(0.5f),
|
2021-06-26 06:08:21 +08:00
|
|
|
|
separator() | inverted,
|
2023-03-27 02:20:02 +08:00
|
|
|
|
gauge(0.1f),
|
2021-06-26 06:08:21 +08:00
|
|
|
|
separator(),
|
|
|
|
|
}),
|
2021-08-09 05:25:20 +08:00
|
|
|
|
text("Test"),
|
2021-06-26 06:08:21 +08:00
|
|
|
|
}) |
|
|
|
|
|
border;
|
|
|
|
|
auto root = gauge(1.0);
|
|
|
|
|
Screen screen(80, state.range(0));
|
|
|
|
|
Render(screen, root);
|
2023-07-29 17:04:24 +08:00
|
|
|
|
screen.ToString();
|
2021-06-26 06:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16);
|
|
|
|
|
|
2023-06-28 04:32:57 +08:00
|
|
|
|
static void BencharkText(benchmark::State& state) {
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
|
std::string content = "HELLO world ";
|
2023-07-15 22:37:50 +08:00
|
|
|
|
for (int i = 0; i < state.range(0); ++i) {
|
2023-06-28 04:32:57 +08:00
|
|
|
|
content += content;
|
|
|
|
|
}
|
|
|
|
|
auto document = paragraph(content);
|
2023-07-15 22:37:50 +08:00
|
|
|
|
Screen screen(200, 200);
|
2023-06-28 04:32:57 +08:00
|
|
|
|
Render(screen, document);
|
2023-07-29 17:04:24 +08:00
|
|
|
|
screen.ToString();
|
2023-06-28 04:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(BencharkText)->DenseRange(0, 10, 1);
|
|
|
|
|
|
2023-07-29 02:54:30 +08:00
|
|
|
|
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),
|
2023-08-01 21:13:04 +08:00
|
|
|
|
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)),
|
2023-07-29 02:54:30 +08:00
|
|
|
|
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);
|
2023-07-29 17:04:24 +08:00
|
|
|
|
screen.ToString();
|
2023-07-29 02:54:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(BenchmarkStyle)
|
|
|
|
|
->ArgsProduct({
|
|
|
|
|
benchmark::CreateDenseRange(1, 10, 3), // Number of elements.
|
|
|
|
|
benchmark::CreateDenseRange(10, 200, 20), // Screen width.
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-17 21:47:20 +08:00
|
|
|
|
} // namespace ftxui
|
2023-03-27 02:20:02 +08:00
|
|
|
|
// NOLINTEND
|
2022-04-17 21:47:20 +08:00
|
|
|
|
|
2021-06-26 06:08:21 +08:00
|
|
|
|
// Copyright 2021 Arthur Sonzogni. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
2023-07-29 02:54:30 +08:00
|
|
|
|
// the LICENSE file.
|