Skip to content

Commit

Permalink
Merge pull request #13 from contour-terminal/improvements/ci
Browse files Browse the repository at this point in the history
CI improvements | some minor termbench API improvements | tb cleanup
  • Loading branch information
christianparpart authored Mar 18, 2024
2 parents 29f1461 + 6dca719 commit cf92f9e
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 113 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ concurrency:

env:
CTEST_OUTPUT_ON_FAILURE: 1
CONTOUR_VERSION: "0.4.3.6442"

jobs:

Expand All @@ -46,8 +47,10 @@ jobs:
ubuntu_linux:
name: "Ubuntu Linux 22.04"
runs-on: ubuntu-22.04
env:
CMAKE_PRESET: "linux-gcc-release"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
Expand All @@ -62,19 +65,20 @@ jobs:
run: |
set -ex
sudo apt -q update
sudo apt install -qy ninja-build
sudo ./scripts/install-deps.sh
- name: "Install GCC 13"
run: sudo apt install g++-13
- name: "cmake"
run: cmake -S . -B build -DCMAKE_BUILD_TYPE="RelWithDebInfo" -D CMAKE_CXX_COMPILER="g++-13"
run: cmake --preset "$CMAKE_PRESET" -D CMAKE_CXX_COMPILER="g++-13"
- name: "build"
run: cmake --build build/ -- -j3
- name: "install dependencies"
run: cmake --build --preset "$CMAKE_PRESET" --preset -- -j3
- name: "install dependencies for running benchmarks"
run: ./scripts/xvfb-deps.sh
- name: "Install contour"
run: |
wget https://github.com/contour-terminal/contour/releases/download/v0.4.3.6442/contour-0.4.3.6442-ubuntu22.04-amd64.deb
sudo dpkg -i contour-0.4.3.6442-ubuntu22.04-amd64.deb
wget https://github.com/contour-terminal/contour/releases/download/v$CONTOUR_VERSION/contour-$CONTOUR_VERSION-ubuntu22.04-amd64.deb
sudo dpkg -i contour-$CONTOUR_VERSION-ubuntu22.04-amd64.deb
- name: "create and patch contour.yml config file"
run: |
set -ex
Expand All @@ -90,7 +94,7 @@ jobs:
- name: "Install kitty and xterm"
run: sudo apt install -y kitty xterm xvfb
- name: "run benchmarks"
run: ./scripts/Xvfb-bench-run.sh ./build/tb/tb
run: ./scripts/Xvfb-bench-run.sh "./build/$CMAKE_PRESET/tb/tb"
- name: "ls"
run: ls -la
- name: "cat contour_results"
Expand All @@ -105,14 +109,12 @@ jobs:
uses: julia-actions/setup-julia@v1
- name: "Create Plots"
run: julia ./scripts/plot_results.jl
- name: "Give result files a .txt file extension"
run: for file in *_results; do mv -v $file $file.txt; done
- name: "Upload results and plot"
uses: actions/upload-artifact@v3
with:
name: benchmark_results
path: |
results_full.png
results_ascii.png
contour_results
alacritty_results
xterm_results
kitty_results
*.png
*_results.txt
2 changes: 1 addition & 1 deletion .github/workflows/disabled/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand Down
52 changes: 20 additions & 32 deletions libtermbench/termbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using namespace std::chrono;
using namespace std::string_view_literals;

namespace contour::termbench
namespace termbench
{

namespace
Expand All @@ -44,14 +44,12 @@ using u16 = unsigned short;

Benchmark::Benchmark(std::function<void(char const*, size_t n)> _writer,
size_t _testSizeMB,
unsigned short _width,
unsigned short _height,
TerminalSize terminalSize,
std::function<void(Test const&)> _beforeTest):
writer_ { std::move(_writer) },
beforeTest_ { std::move(_beforeTest) },
testSizeMB_ { _testSizeMB },
width_ { _width },
height_ { _height }
terminalSize_ { terminalSize }
{
}

Expand Down Expand Up @@ -81,7 +79,7 @@ void Benchmark::runAll()
if (beforeTest_)
beforeTest_(*test);

test->setup(width_, height_);
test->setup(terminalSize_);
test->run(*buffer);

auto const beginTime = steady_clock::now();
Expand All @@ -104,7 +102,7 @@ void Benchmark::summarize(std::ostream& os)
{
os << std::format("All {} tests finished.\n", results_.size());
os << std::format("---------------------\n\n");
auto const gridCellCount = width_ * height_;
auto const gridCellCount = terminalSize_.columns * terminalSize_.lines;

std::chrono::milliseconds totalTime {};
size_t totalBytes = 0;
Expand All @@ -130,13 +128,13 @@ void Benchmark::summarize(std::ostream& os)
sizeStr(bps),
sizeStr(bps / static_cast<double>(gridCellCount)));
os << "\n";
os << std::format(" screen size: {}x{}\n", width_, height_);
os << std::format(" screen size: {}x{}\n", terminalSize_.columns, terminalSize_.lines);
os << std::format(" data size: {}\n", sizeStr(static_cast<double>(testSizeMB_ * 1024 * 1024)));
}

} // namespace contour::termbench
} // namespace termbench

namespace contour::termbench::tests
namespace termbench::tests
{

namespace
Expand Down Expand Up @@ -204,7 +202,7 @@ namespace
public:
ManyLines() noexcept: Test("many_lines", "") {}

void setup(unsigned short, unsigned short) override
void setup(TerminalSize) override
{
text.resize(4 * 1024 * 1024);
for (auto i = text.data(), e = i + text.size(); i != e; ++i)
Expand Down Expand Up @@ -246,23 +244,18 @@ namespace
public:
SgrFgColoredText() noexcept: Test("sgr_fg_lines", "") {}

unsigned short width = 80;
unsigned short height = 24;
TerminalSize terminalSize;

void setup(unsigned short _width, unsigned short _height) noexcept override
{
width = _width;
height = _height;
}
void setup(TerminalSize size) noexcept override { terminalSize = size; }

void run(Buffer& _sink) noexcept override
{
for (unsigned frameID = 0; _sink.good(); ++frameID)
{
for (u16 y = 0; y < height; ++y)
for (u16 y = 0; y < terminalSize.lines; ++y)
{
moveCursor(_sink, 1, y + 1u);
for (u16 x = 0; x < width; ++x)
for (u16 x = 0; x < terminalSize.columns; ++x)
{
auto const r = frameID;
auto const g = frameID + y;
Expand All @@ -281,23 +274,18 @@ namespace
public:
SgrFgBgColoredText() noexcept: Test("sgr_fg_bg_lines", "") {}

unsigned short width = 80;
unsigned short height = 24;
TerminalSize terminalSize;

void setup(unsigned short _width, unsigned short _height) noexcept override
{
width = _width;
height = _height;
}
void setup(TerminalSize size) noexcept override { terminalSize = size; }

void run(Buffer& _sink) noexcept override
{
for (unsigned frameID = 0; _sink.good(); ++frameID)
{
for (u16 y = 0; y < height; ++y)
for (u16 y = 0; y < terminalSize.lines; ++y)
{
moveCursor(_sink, 1, y + 1u);
for (u16 x = 0; x < width; ++x)
for (u16 x = 0; x < terminalSize.columns; ++x)
{
auto r = static_cast<uint8_t>(frameID);
auto g = static_cast<uint8_t>(frameID + y);
Expand All @@ -321,7 +309,7 @@ namespace
public:
Binary() noexcept: Test("binary", "") {}

void setup(unsigned short, unsigned short) override
void setup(TerminalSize) override
{
text.resize(4 * 1024 * 1024);
for (auto i = text.data(), e = i + text.size(); i != e; ++i)
Expand Down Expand Up @@ -352,7 +340,7 @@ namespace
{
public:
Line(std::string name, std::string text): Test(name, ""), text { text } {}
void setup(unsigned short, unsigned short) override {}
void setup(TerminalSize) override {}

void run(Buffer& _sink) noexcept override
{
Expand Down Expand Up @@ -422,4 +410,4 @@ std::unique_ptr<Test> sgrbg_line(size_t N)
return std::make_unique<Line>(name, text);
}

} // namespace contour::termbench::tests
} // namespace termbench::tests
28 changes: 17 additions & 11 deletions libtermbench/termbench.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@
#include <string_view>
#include <vector>

namespace contour::termbench
namespace termbench
{

struct TerminalSize
{
unsigned short columns = 0;
unsigned short lines = 0;

constexpr auto operator<=>(TerminalSize const&) const noexcept = default;
};

struct Buffer
{
public:
Expand Down Expand Up @@ -68,9 +76,9 @@ struct Test
{
}

virtual void setup(unsigned short, unsigned short) {}
virtual void run(Buffer&) noexcept = 0;
virtual void teardown(Buffer&) {}
virtual void setup(TerminalSize /*terminalSize*/) {}
virtual void run(Buffer& /*stdoutBuffer*/) noexcept = 0;
virtual void teardown(Buffer& /*stdoutBuffer*/) {}
};

struct Result
Expand All @@ -85,8 +93,7 @@ class Benchmark
public:
Benchmark(std::function<void(char const*, size_t n)> _writer,
size_t _testSizeMB,
unsigned short _width,
unsigned short _height,
TerminalSize terminalSize,
std::function<void(Test const&)> _beforeTest = {});

void add(std::unique_ptr<Test> _test);
Expand All @@ -105,17 +112,16 @@ class Benchmark
std::function<void(char const*, size_t)> writer_;
std::function<void(Test const&)> beforeTest_;
size_t testSizeMB_;
unsigned short width_;
unsigned short height_;
TerminalSize terminalSize_;

std::vector<std::unique_ptr<Test>> tests_;
std::vector<Result> results_;
};

} // namespace contour::termbench
} // namespace termbench

// Holds a set of pre-defined terminal benchmark tests.
namespace contour::termbench::tests
namespace termbench::tests
{
std::unique_ptr<Test> many_lines();
std::unique_ptr<Test> long_lines();
Expand All @@ -125,4 +131,4 @@ std::unique_ptr<Test> binary();
std::unique_ptr<Test> ascii_line(size_t);
std::unique_ptr<Test> sgr_line(size_t);
std::unique_ptr<Test> sgrbg_line(size_t);
} // namespace contour::termbench::tests
} // namespace termbench::tests
Loading

0 comments on commit cf92f9e

Please sign in to comment.