libgrapheme

unicode string library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | README | LICENSE

commit 2ea6826b9be5ae9ffab21b623c4b2a5dfdb365d9
parent 4d157807af659ec392043cffd36935eba8c634af
Author: Laslo Hunhold <dev@frign.de>
Date:   Sat,  8 Jan 2022 17:04:35 +0100

Add comment-parameter to benchmark for optional further context

I noticed that the utf8proc-decoder does not handle overlong encodings
(if I'm not mistaken), which is quite dangerous as you can shadow a
NUL-byte which can lead to memory corruption and reading (remember
Heartbleed?).

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mbenchmark/character.c | 4++--
Mbenchmark/utf8-decode.c | 9+++++----
Mbenchmark/util.c | 11+++++++----
Mbenchmark/util.h | 2+-
4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/benchmark/character.c b/benchmark/character.c @@ -80,9 +80,9 @@ main(int argc, char *argv[]) } printf("%s\n", argv[0]); - run_benchmark(libgrapheme, &p, "libgrapheme ", "comparison", + run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, "comparison", &baseline, NUM_ITERATIONS, p.bufsiz - 1); - run_benchmark(libutf8proc, &p, "libutf8proc ", "comparison", + run_benchmark(libutf8proc, &p, "libutf8proc ", NULL, "comparison", &baseline, NUM_ITERATIONS, p.bufsiz - 1); free(p.buf); diff --git a/benchmark/utf8-decode.c b/benchmark/utf8-decode.c @@ -107,10 +107,11 @@ main(int argc, char *argv[]) } printf("%s\n", argv[0]); - run_benchmark(libgrapheme, &p, "libgrapheme ", "byte", &baseline, - NUM_ITERATIONS, p.bufsiz); - run_benchmark(libutf8proc, &p, "libutf8proc ", "byte", &baseline, - NUM_ITERATIONS, p.bufsiz); + run_benchmark(libgrapheme, &p, "libgrapheme ", NULL, + "byte", &baseline, NUM_ITERATIONS, p.bufsiz); + run_benchmark(libutf8proc, &p, "libutf8proc ", + "but unsafe (does not detect overlong encodings)", + "byte", &baseline, NUM_ITERATIONS, p.bufsiz); free(cpbuf); free(p.buf_char); diff --git a/benchmark/util.c b/benchmark/util.c @@ -39,8 +39,9 @@ time_diff(struct timespec *a, struct timespec *b) void run_benchmark(void (*func)(const void *), const void *payload, - const char *name, const char *unit, double *baseline, - size_t num_iterations, size_t units_per_iteration) + const char *name, const char *comment, const char *unit, + double *baseline, size_t num_iterations, + size_t units_per_iteration) { struct timespec start, end; size_t i; @@ -66,8 +67,10 @@ run_benchmark(void (*func)(const void *), const void *payload, *baseline = diff; printf(" avg. %.3es/%s (baseline)\n", diff, unit); } else { - printf(" avg. %.3es/%s (%.2f%% %s)\n", diff, unit, + printf(" avg. %.3es/%s (%.2f%% %s%s%s)\n", diff, unit, fabs(1.0 - diff / *baseline) * 100, - (diff < *baseline) ? "faster" : "slower"); + (diff < *baseline) ? "faster" : "slower", + comment ? ", " : "", + comment ? comment : ""); } } diff --git a/benchmark/util.h b/benchmark/util.h @@ -8,6 +8,6 @@ uint_least32_t *generate_test_buffer(const struct test *, size_t, size_t *); void run_benchmark(void (*func)(const void *), const void *, const char *, - const char *, double *, size_t, size_t); + const char *, const char *, double *, size_t, size_t); #endif /* UTIL_H */