aboutsummaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
Diffstat (limited to 'bench')
-rw-r--r--bench/.gitignore4
-rw-r--r--bench/bench.c108
-rw-r--r--bench/bench.h49
-rw-r--r--bench/compose.c81
-rw-r--r--bench/key-proc.c94
-rw-r--r--bench/rules.c70
-rw-r--r--bench/rulescomp.c63
7 files changed, 469 insertions, 0 deletions
diff --git a/bench/.gitignore b/bench/.gitignore
new file mode 100644
index 0000000..cd32dfc
--- /dev/null
+++ b/bench/.gitignore
@@ -0,0 +1,4 @@
+key-proc
+rules
+rulescomp
+compose
diff --git a/bench/bench.c b/bench/bench.c
new file mode 100644
index 0000000..c28ac65
--- /dev/null
+++ b/bench/bench.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2015 Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>
+ * Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "bench.h"
+#include "../src/utils.h"
+
+#ifndef _MSC_VER
+#include <sys/time.h>
+#else
+#include <windows.h>
+#include <stdint.h>
+
+struct timeval {
+ long tv_sec, tv_usec;
+};
+
+static int
+gettimeofday(struct timeval *tv, void *unused)
+{
+ static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
+
+ SYSTEMTIME system_time;
+ FILETIME file_time;
+ uint64_t t;
+
+ GetSystemTime(&system_time);
+ SystemTimeToFileTime(&system_time, &file_time);
+ t = (uint64_t) file_time.dwLowDateTime;
+ t += ((uint64_t) file_time.dwHighDateTime) << 32;
+
+ tv->tv_sec = (long) ((t - EPOCH) / 10000000L);
+ tv->tv_usec = (long) (system_time.wMilliseconds * 1000);
+ return 0;
+}
+#endif
+
+void
+bench_start(struct bench *bench)
+{
+ struct timeval val;
+ (void) gettimeofday(&val, NULL);
+ bench->start = (struct bench_time) {
+ .seconds = val.tv_sec,
+ .microseconds = val.tv_usec,
+ };
+}
+
+void
+bench_stop(struct bench *bench)
+{
+ struct timeval val;
+ (void) gettimeofday(&val, NULL);
+ bench->stop = (struct bench_time) {
+ .seconds = val.tv_sec,
+ .microseconds = val.tv_usec,
+ };
+}
+
+void
+bench_elapsed(const struct bench *bench, struct bench_time *result)
+{
+ result->seconds = bench->stop.seconds - bench->start.seconds;
+ result->microseconds = bench->stop.microseconds - bench->start.microseconds;
+ if (result->microseconds < 0) {
+ result->microseconds += 1000000;
+ result->seconds--;
+ }
+}
+
+char *
+bench_elapsed_str(const struct bench *bench)
+{
+ struct bench_time elapsed;
+ char *buf;
+ int ret;
+
+ bench_elapsed(bench, &elapsed);
+ ret = asprintf(&buf, "%ld.%06ld", elapsed.seconds, elapsed.microseconds);
+ assert(ret >= 0);
+
+ return buf;
+}
diff --git a/bench/bench.h b/bench/bench.h
new file mode 100644
index 0000000..facee3d
--- /dev/null
+++ b/bench/bench.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2015 Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>
+ * Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef LIBXKBCOMMON_BENCH_H
+#define LIBXKBCOMMON_BENCH_H
+
+struct bench_time {
+ long seconds;
+ long microseconds;
+};
+
+struct bench {
+ struct bench_time start;
+ struct bench_time stop;
+};
+
+void
+bench_start(struct bench *bench);
+void
+bench_stop(struct bench *bench);
+
+void
+bench_elapsed(const struct bench *bench, struct bench_time *result);
+/* The caller is responsibile to free() the returned string. */
+char *
+bench_elapsed_str(const struct bench *bench);
+
+#endif /* LIBXKBCOMMON_BENCH_H */
diff --git a/bench/compose.c b/bench/compose.c
new file mode 100644
index 0000000..7ff0798
--- /dev/null
+++ b/bench/compose.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright © 2014 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <time.h>
+
+#include "xkbcommon/xkbcommon-compose.h"
+
+#include "../test/test.h"
+#include "bench.h"
+
+#define BENCHMARK_ITERATIONS 1000
+
+int
+main(void)
+{
+ struct xkb_context *ctx;
+ char *path;
+ FILE *file;
+ struct xkb_compose_table *table;
+ struct bench bench;
+ char *elapsed;
+
+ ctx = test_get_context(CONTEXT_NO_FLAG);
+ assert(ctx);
+
+ path = test_get_path("compose/en_US.UTF-8/Compose");
+ file = fopen(path, "rb");
+ if (file == NULL) {
+ perror(path);
+ free(path);
+ xkb_context_unref(ctx);
+ return -1;
+ }
+
+ xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
+ xkb_context_set_log_verbosity(ctx, 0);
+
+ bench_start(&bench);
+ for (int i = 0; i < BENCHMARK_ITERATIONS; i++) {
+ rewind(file);
+ table = xkb_compose_table_new_from_file(ctx, file, "",
+ XKB_COMPOSE_FORMAT_TEXT_V1,
+ XKB_COMPOSE_COMPILE_NO_FLAGS);
+ assert(table);
+ xkb_compose_table_unref(table);
+ }
+ bench_stop(&bench);
+
+ fclose(file);
+ free(path);
+
+ elapsed = bench_elapsed_str(&bench);
+ fprintf(stderr, "compiled %d compose tables in %ss\n",
+ BENCHMARK_ITERATIONS, elapsed);
+ free(elapsed);
+
+ xkb_context_unref(ctx);
+ return 0;
+}
diff --git a/bench/key-proc.c b/bench/key-proc.c
new file mode 100644
index 0000000..1d29243
--- /dev/null
+++ b/bench/key-proc.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2012 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <time.h>
+
+#include "../test/test.h"
+#include "bench.h"
+
+#define BENCHMARK_ITERATIONS 20000000
+
+static void
+bench_key_proc(struct xkb_state *state)
+{
+ int8_t keys[256] = { 0 };
+ xkb_keycode_t keycode;
+ xkb_keysym_t keysym;
+ int i;
+
+ for (i = 0; i < BENCHMARK_ITERATIONS; i++) {
+ keycode = (rand() % (255 - 9)) + 9;
+ if (keys[keycode]) {
+ xkb_state_update_key(state, keycode, XKB_KEY_UP);
+ keys[keycode] = 0;
+ keysym = xkb_state_key_get_one_sym(state, keycode);
+ (void) keysym;
+ } else {
+ xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
+ keys[keycode] = 1;
+ }
+ }
+}
+
+int
+main(void)
+{
+ struct xkb_context *ctx;
+ struct xkb_keymap *keymap;
+ struct xkb_state *state;
+ struct bench bench;
+ char *elapsed;
+
+ ctx = test_get_context(0);
+ assert(ctx);
+
+ keymap = test_compile_rules(ctx, "evdev", "pc104", "us,ru,il,de",
+ ",,,neo", "grp:menu_toggle");
+ assert(keymap);
+
+ state = xkb_state_new(keymap);
+ assert(state);
+
+ xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
+ xkb_context_set_log_verbosity(ctx, 0);
+
+ srand((unsigned) time(NULL));
+
+ bench_start(&bench);
+ bench_key_proc(state);
+ bench_stop(&bench);
+
+ elapsed = bench_elapsed_str(&bench);
+ fprintf(stderr, "ran %d iterations in %ss\n",
+ BENCHMARK_ITERATIONS, elapsed);
+ free(elapsed);
+
+ xkb_state_unref(state);
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(ctx);
+
+ return 0;
+}
diff --git a/bench/rules.c b/bench/rules.c
new file mode 100644
index 0000000..3206583
--- /dev/null
+++ b/bench/rules.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2012 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <time.h>
+
+#include "../test/test.h"
+#include "xkbcomp/xkbcomp-priv.h"
+#include "xkbcomp/rules.h"
+#include "bench.h"
+
+#define BENCHMARK_ITERATIONS 20000
+
+int
+main(int argc, char *argv[])
+{
+ struct xkb_context *ctx;
+ int i;
+ struct xkb_rule_names rmlvo = {
+ "evdev", "pc105", "us,il", ",", "ctrl:nocaps,grp:menu_toggle",
+ };
+ struct xkb_component_names kccgst;
+ struct bench bench;
+ char *elapsed;
+
+ ctx = test_get_context(0);
+ assert(ctx);
+
+ xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
+ xkb_context_set_log_verbosity(ctx, 0);
+
+ bench_start(&bench);
+ for (i = 0; i < BENCHMARK_ITERATIONS; i++) {
+ assert(xkb_components_from_rules(ctx, &rmlvo, &kccgst));
+ free(kccgst.keycodes);
+ free(kccgst.types);
+ free(kccgst.compat);
+ free(kccgst.symbols);
+ }
+ bench_stop(&bench);
+
+ elapsed = bench_elapsed_str(&bench);
+ fprintf(stderr, "processed %d rule files in %ss\n",
+ BENCHMARK_ITERATIONS, elapsed);
+ free(elapsed);
+
+ xkb_context_unref(ctx);
+ return 0;
+}
diff --git a/bench/rulescomp.c b/bench/rulescomp.c
new file mode 100644
index 0000000..3972a7b
--- /dev/null
+++ b/bench/rulescomp.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2009 Dan Nicholson
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <time.h>
+
+#include "../test/test.h"
+#include "bench.h"
+
+#define BENCHMARK_ITERATIONS 2500
+
+int
+main(int argc, char *argv[])
+{
+ struct xkb_context *ctx;
+ struct xkb_keymap *keymap;
+ struct bench bench;
+ char *elapsed;
+ int i;
+
+ ctx = test_get_context(0);
+ assert(ctx);
+
+ xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
+ xkb_context_set_log_verbosity(ctx, 0);
+
+ bench_start(&bench);
+ for (i = 0; i < BENCHMARK_ITERATIONS; i++) {
+ keymap = test_compile_rules(ctx, "evdev", "evdev", "us", "", "");
+ assert(keymap);
+ xkb_keymap_unref(keymap);
+ }
+ bench_stop(&bench);
+
+ elapsed = bench_elapsed_str(&bench);
+ fprintf(stderr, "compiled %d keymaps in %ss\n",
+ BENCHMARK_ITERATIONS, elapsed);
+ free(elapsed);
+
+ xkb_context_unref(ctx);
+ return 0;
+}