Skip to content

Commit

Permalink
Add some benchmarks with unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Mar 20, 2024
1 parent 760c9c3 commit 3728ab7
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 37 deletions.
Binary file added benchmark_results.zip
Binary file not shown.
78 changes: 63 additions & 15 deletions libtermbench/termbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void Benchmark::updateWindowTitle(std::string_view _title)
std::cout.flush();
}


void Benchmark::writeOutput(Buffer const& testBuffer)
{
auto const output = testBuffer.output();
Expand Down Expand Up @@ -390,35 +389,84 @@ std::unique_ptr<Test> binary()
return std::make_unique<Binary>();
}

std::unique_ptr<Test> ascii_line(size_t N)
std::unique_ptr<Test> ascii_line(size_t line_length)
{
auto name = std::to_string(N) + " chars per line";
auto text = std::string(N, 'a') + std::string { "\n" };
auto name = std::to_string(line_length) + " chars per line";
auto text = std::string(line_length, 'a') + std::string { "\n" };
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> sgr_line(size_t N)
std::unique_ptr<Test> sgr_line(size_t line_length)
{
auto name = std::to_string(N) + " chars with sgr per line";
auto name = std::to_string(line_length) + " chars with sgr per line";
std::string text {};
text += std::string { "\033[38;2;20;200;200m" };
text += std::string(N, 'a');
text += std::string { "\n" };
text += std::string { "\033[38;2;255;255;255m" };
text += "\033[38;2;20;200;200m";
text += std::string(line_length, 'a');
text += "\n";
text += "\033[38;2;255;255;255m";
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> sgrbg_line(size_t line_length)
{
auto name = std::to_string(line_length) + " chars with sgr and bg per line";
std::string text {};
text += "\033[38;2;20;200;200m\033[48;2;100;100;100m";
text += std::string(line_length, 'a');
text += "\033[38;2;255;255;255m\033[48;2;0;0;0m";
text += "\n";
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> unicode_simple(size_t line_length)
{
auto name = std::to_string(line_length) + " unicode simple";
std::string text {};
for (size_t i = 0; i < line_length; ++i)
text += "\u0041";
text += "\n";
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> unicode_two_codepoints(size_t line_length)
{
auto name = std::to_string(line_length) + " unicode diacritic";
std::string text {};
for (size_t i = 0; i < line_length; ++i)
text += "\u0041\u0308";
text += "\n";
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> sgrbg_line(size_t N)
std::unique_ptr<Test> unicode_fire(size_t line_length)
{
auto name = std::to_string(N) + " chars with sgr and bg per line";
auto name = std::to_string(line_length) + " unicode fire";
std::string text {};
text += std::string { "\033[38;2;20;200;200m\033[48;2;100;100;100m" };
text += std::string(N, 'a');
text += std::string { "\033[38;2;255;255;255m\033[48;2;0;0;0m" };
for (size_t i = 0; i < line_length; ++i)
text += std::string { "\U0001F525" };
text += std::string { "\n" };
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> unicode_flag(size_t line_length)
{
auto name = std::to_string(line_length) + " unicode flag";
std::string text {};
std::string flag {};
flag += "\U0001F3F4";
flag += "\U000E0067";
flag += "\U000E0062";
flag += "\U000E0065";
flag += "\U000E006E";
flag += "\U000E0067";
flag += "\U000E007F";

for (size_t i = 0; i < line_length; ++i)
text += flag;
text += "\n";
return std::make_unique<Line>(name, text);
}

std::unique_ptr<Test> crafted(std::string name, std::string description, std::string text)
{
return std::make_unique<CraftedTest>(std::move(name), std::move(description), std::move(text));
Expand Down
4 changes: 4 additions & 0 deletions libtermbench/termbench.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,9 @@ 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);
std::unique_ptr<Test> unicode_simple(size_t);
std::unique_ptr<Test> unicode_two_codepoints(size_t);
std::unique_ptr<Test> unicode_flag(size_t);
std::unique_ptr<Test> unicode_fire(size_t);
std::unique_ptr<Test> crafted(std::string name, std::string description, std::string text);
} // namespace termbench::tests
8 changes: 4 additions & 4 deletions scripts/Xvfb-bench-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ function program_exit() {
function bench_terminal() {
printf "\033[1m==> Running terminal: $1\033[m\n"
local terminal_name=$(basename $1)
time "${@}" -e "${TB_BIN}" --fixed-size --stdout-fastpath --column-by-column --output "${OUTPUT_DIR}/${terminal_name}_results"
time "${@}" -e "${TB_BIN}" --fixed-size --column-by-column --size 10 --output "${OUTPUT_DIR}/${terminal_name}_results"
local exit_code=$?
printf "\033[1m==> Terminal exit code: $exit_code\033[m\n"
if [[ $exit_code -ne 0 ]]; then
program_exit $exit_code
fi
# if [[ $exit_code -ne 0 ]]; then
# program_exit $exit_code
# fi
}

set -x
Expand Down
53 changes: 37 additions & 16 deletions scripts/plot_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ end

function get_data(data, data_type)
if data_type == :ascii
name = "chars per line"
name = "chars per line:"
elseif data_type == :sgr
name = "chars with sgr per line"
name = "chars with sgr per line:"
elseif data_type == :sgr_bg
name = "chars with sgr and bg per line"
name = "chars with sgr and bg per line:"
elseif data_type == :unicode
name = "unicode simple:"
elseif data_type == :diacritic
name = "unicode diacritic:"
elseif data_type == :fire
name = "unicode fire:"
elseif data_type == :flag
name = "unicode flag:"
end

lines = []
Expand All @@ -38,7 +46,8 @@ end



function generate_for_terminal(file_name)
function generate_for_terminal(file_name, prefix="results_")
try
terminal_name = split(file_name,"_")[1]

fig = Figure()
Expand All @@ -47,21 +56,25 @@ function generate_for_terminal(file_name)
data = split(open(io->read(io, String), file_name), '\n')
terminal_name = split(file_name,"_")[1]

markers = [:circle :rect :cross :star4 :start5 :star6]

get_data_l = (type) -> get_data(data,type)
ascii_speed = get_data_l(:ascii)
sgr_speed = get_data_l(:sgr)
sgr_bg_speed = get_data_l(:sgr_bg)
speed = [ get_data_l(t) for t in types]

marker_size = 8
scatter!(ax,ascii_speed, label= terminal_name * "_ascii", marker = :circle, markersize = marker_size)
scatter!(ax,sgr_speed, label=terminal_name*"_sgr", marker = :rect, markersize = marker_size)
scatter!(ax,sgr_bg_speed, label=terminal_name*"_sgr_and_bg", marker = :cross, markersize = marker_size)
for (ind,dat) in enumerate(speed)
scatter!(ax,dat, label= terminal_name * "_" * string(types[ind]), marker = markers[ind], markersize = marker_size)
end
axislegend(position = :rt)

save("results_"*terminal_name*".png", fig)
save(prefix*terminal_name*".png", fig)
catch e
println(e)
end
end

function generate_comparison(type)
try
fig = Figure()
ax = Axis(fig[1,1], title = "Comparison for "*string(type), xlabel = "Length of line", ylabel = "throughput, MB/s")

Expand All @@ -71,15 +84,23 @@ function generate_comparison(type)
insert_from_data(ax,"kitty_results",:utriangle, type)
axislegend(position = :lt)
return fig
catch e
println(e)
end
end


types = [:ascii :sgr :sgr_bg ]
generate_for_terminal("contour_results")
generate_for_terminal("alacritty_results")
generate_for_terminal("xterm_results")
generate_for_terminal("kitty_results")


save("comparison_ascii.png", generate_comparison(:ascii))
save("comparison_sgr.png", generate_comparison(:sgr))
save("comparison_sgr_bg.png", generate_comparison(:sgr_bg))
types = [:unicode :fire :flag :diacritic]
generate_for_terminal_l = (n) -> generate_for_terminal(n, "results_unicode_")
generate_for_terminal_l("contour_results")
generate_for_terminal_l("alacritty_results")
generate_for_terminal_l("xterm_results")
generate_for_terminal_l("kitty_results")

types = [:ascii :sgr :sgr_bg :unicode :fire :flag :diacritic]
[ save("comparison"*string(type)*".png", generate_comparison(type)) for type in types ]
13 changes: 11 additions & 2 deletions tb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ BenchSettings parseArguments(int argc, char const* argv[], TerminalSize const& i
}
else if (argv[i] == "--fixed-size"sv)
{
settings.requestedTerminalSize.columns = 200;
settings.requestedTerminalSize.columns = 100;
settings.requestedTerminalSize.lines = 30;
}
else if (argv[i] == "--stdout-fastpath"sv)
Expand Down Expand Up @@ -189,11 +189,13 @@ std::string loadFileContents(std::filesystem::path const& path)

bool addTestsToBenchmark(termbench::Benchmark& tb, BenchSettings const& settings)
{
/*
tb.add(termbench::tests::many_lines());
tb.add(termbench::tests::long_lines());
tb.add(termbench::tests::sgr_fg_lines());
tb.add(termbench::tests::sgr_fgbg_lines());
tb.add(termbench::tests::binary());
*/
// TODO: The above tests should also be configurable via command line (-mlfgb).

for (auto const& test: settings.craftedTests)
Expand All @@ -212,12 +214,19 @@ bool addTestsToBenchmark(termbench::Benchmark& tb, BenchSettings const& settings
auto const maxColumns { settings.requestedTerminalSize.columns * 2u };
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::ascii_line(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::unicode_simple(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::unicode_two_codepoints(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::unicode_fire(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::unicode_flag(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::sgr_line(i));
for (size_t i = 0; i < maxColumns; ++i)
tb.add(termbench::tests::sgrbg_line(i));
}

return true;
}

Expand Down

0 comments on commit 3728ab7

Please sign in to comment.