Skip to content

Commit

Permalink
compose: Bench traversal using foreach implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Aug 28, 2024
1 parent f5cacd8 commit 8364e17
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
28 changes: 21 additions & 7 deletions bench/compose-traversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,35 @@

#include "config.h"

#include <string.h>
#include <time.h>

#include "xkbcommon/xkbcommon-compose.h"

#include "../test/compose-iter.h"
#include "../test/test.h"
#include "bench.h"

#define BENCHMARK_ITERATIONS 1000

static void
compose_fn(struct xkb_compose_table_entry *entry, void *data)
{
assert (entry);
}

int
main(void)
main(int argc, char *argv[])
{
struct xkb_context *ctx;
char *path;
FILE *file;
struct xkb_compose_table *table;
struct xkb_compose_table_iterator *iter;
struct xkb_compose_table_entry *entry;
struct bench bench;
char *elapsed;

bool use_foreach = (argc > 1 && strcmp(argv[1], "foreach") == 0);

ctx = test_get_context(CONTEXT_NO_FLAG);
assert(ctx);

Expand All @@ -68,11 +76,17 @@ main(void)

bench_start(&bench);
for (int i = 0; i < BENCHMARK_ITERATIONS; i++) {
iter = xkb_compose_table_iterator_new(table);
while ((entry = xkb_compose_table_iterator_next(iter))) {
assert (entry);
if (use_foreach) {
xkb_compose_table_for_each(table, compose_fn, NULL);
} else {
struct xkb_compose_table_iterator *iter;
struct xkb_compose_table_entry *entry;
iter = xkb_compose_table_iterator_new(table);
while ((entry = xkb_compose_table_iterator_next(iter))) {
assert (entry);
}
xkb_compose_table_iterator_free(iter);
}
xkb_compose_table_iterator_free(iter);
}
bench_stop(&bench);

Expand Down
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,15 @@ benchmark(
)
benchmark(
'compose-traversal',
executable('bench-compose-traversal', 'bench/compose-traversal.c', dependencies: test_dep),
executable(
'bench-compose-traversal',
'bench/compose-traversal.c',
'bench/bench.h',
'test/compose-iter.c',
'test/compose-iter.h',
'test/test.h',
dependencies: test_dep
),
env: bench_env,
)
benchmark(
Expand Down

0 comments on commit 8364e17

Please sign in to comment.