From a1098bc1345189bd389865482d7561d56dd6a3c5 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Mon, 16 Mar 2026 11:16:41 -0700 Subject: [PATCH] feat: Add benchmarking for libx52util-bmp-test --- libx52util/meson.build | 4 ++++ libx52util/x52_char_map_test.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libx52util/meson.build b/libx52util/meson.build index 9950605..63b7dee 100644 --- a/libx52util/meson.build +++ b/libx52util/meson.build @@ -34,3 +34,7 @@ libx52util_bmp_test = executable( test('libx52util-bmp-test', libx52util_bmp_test, protocol: 'tap', args: [util_char_map[1]]) + +benchmark('libx52util-bmp-bench', libx52util_bmp_test, + protocol: 'tap', + args: [util_char_map[1]]) diff --git a/libx52util/x52_char_map_test.c b/libx52util/x52_char_map_test.c index 8648fe8..afb1677 100644 --- a/libx52util/x52_char_map_test.c +++ b/libx52util/x52_char_map_test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "libx52util.h" @@ -61,6 +62,11 @@ static void encode_utf8(uint32_t cp, uint8_t *out) } } +static double get_time_diff(struct timespec start, struct timespec end) +{ + return (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9; +} + int main(int argc, char *argv[]) { uint8_t input[8] = {0}; @@ -72,6 +78,8 @@ int main(int argc, char *argv[]) uint8_t *expected_blob; bool smp_pages_ok; + struct timespec start, end; + // Argument check if (argc != 2) { puts("Bail out! Invalid number of arguments"); @@ -97,6 +105,8 @@ int main(int argc, char *argv[]) // Check the 256 BMP Pages, plus the supplementary pages puts("1..257"); + clock_gettime(CLOCK_MONOTONIC, &start); + for (uint32_t page = 0; page < 256; page++) { bool page_ok = true; @@ -141,6 +151,16 @@ int main(int argc, char *argv[]) page + 1, page); } + clock_gettime(CLOCK_MONOTONIC, &end); + { + double time_spent = get_time_diff(start, end); + printf("# -- Benchmark results --\n"); + printf("# Total time for 64K lookups: %.4f seconds\n", time_spent); + printf("# Throughput: %.2f Mchars/sec\n", (65536.0 / time_spent) / 1e6); + + printf("# -----------------------\n"); + } + // Handle the supplementary pages smp_pages_ok = true; for (uint32_t smp = 0x1; smp <= 0x10; smp++) {