summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2014-10-02 22:03:28 +0300
committerRan Benita <ran234@gmail.com>2014-10-02 22:03:28 +0300
commitbc3b4c084a4b4858319ba4843fae99b6fb77994a (patch)
tree6b286e1201f5ca30f29122f512652fe59db35d31
parentfd126551ed81c21800fdabe918c48b51c5bf27d9 (diff)
downloadxorg-lib-libxkbcommon-bc3b4c084a4b4858319ba4843fae99b6fb77994a.tar.gz
Move benchmarks from tests to their own files in bench/
The tests only contain tests, and the benchmarks are more visible. Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r--Makefile.am22
-rw-r--r--bench/.gitignore3
-rw-r--r--bench/key-proc.c (renamed from test/bench-key-proc.c)2
-rw-r--r--bench/rules.c71
-rw-r--r--bench/rulescomp.c64
-rw-r--r--test/.gitignore1
-rw-r--r--test/rules-file.c48
-rw-r--r--test/rulescomp.c55
8 files changed, 157 insertions, 109 deletions
diff --git a/Makefile.am b/Makefile.am
index 01d39ce..0bae4ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -180,8 +180,7 @@ TESTS = \
test/rulescomp
check_PROGRAMS = \
test/rmlvo-to-kccgst \
- test/print-compiled-keymap \
- test/bench-key-proc
+ test/print-compiled-keymap
TESTS_LDADD = libtest.la
@@ -189,7 +188,7 @@ test_keysym_LDADD = $(TESTS_LDADD)
test_filecomp_LDADD = $(TESTS_LDADD)
test_context_LDADD = $(TESTS_LDADD)
test_rules_file_CFLAGS = $(AM_CFLAGS) -Wno-declaration-after-statement
-test_rules_file_LDADD = $(TESTS_LDADD) -lrt
+test_rules_file_LDADD = $(TESTS_LDADD)
test_stringcomp_LDADD = $(TESTS_LDADD)
test_buffercomp_LDADD = $(TESTS_LDADD)
test_log_LDADD = $(TESTS_LDADD)
@@ -197,10 +196,9 @@ test_atom_LDADD = $(TESTS_LDADD)
test_utf8_LDADD = $(TESTS_LDADD)
test_state_LDADD = $(TESTS_LDADD)
test_keyseq_LDADD = $(TESTS_LDADD)
-test_rulescomp_LDADD = $(TESTS_LDADD) -lrt
+test_rulescomp_LDADD = $(TESTS_LDADD)
test_rmlvo_to_kccgst_LDADD = $(TESTS_LDADD)
test_print_compiled_keymap_LDADD = $(TESTS_LDADD)
-test_bench_key_proc_LDADD = $(TESTS_LDADD) -lrt
if BUILD_LINUX_TESTS
check_PROGRAMS += \
@@ -230,6 +228,20 @@ endif ENABLE_X11
check_PROGRAMS += $(TESTS)
##
+# Benchmarks
+##
+
+BENCH_LDADD = $(TESTS_LDADD) -lrt
+
+check_PROGRAMS += \
+ bench/key-proc \
+ bench/rules \
+ bench/rulescomp
+bench_key_proc_LDADD = $(BENCH_LDADD)
+bench_rules_LDADD = $(BENCH_LDADD)
+bench_rulescomp_LDADD = $(BENCH_LDADD)
+
+##
# Custom targets
##
diff --git a/bench/.gitignore b/bench/.gitignore
new file mode 100644
index 0000000..bf688ae
--- /dev/null
+++ b/bench/.gitignore
@@ -0,0 +1,3 @@
+key-proc
+rules
+rulescomp
diff --git a/test/bench-key-proc.c b/bench/key-proc.c
index e345092..255f033 100644
--- a/test/bench-key-proc.c
+++ b/bench/key-proc.c
@@ -24,7 +24,7 @@
#include <stdlib.h>
#include <time.h>
-#include "test.h"
+#include "../test/test.h"
#define BENCHMARK_ITERATIONS 20000000
diff --git a/bench/rules.c b/bench/rules.c
new file mode 100644
index 0000000..d92ed07
--- /dev/null
+++ b/bench/rules.c
@@ -0,0 +1,71 @@
+/*
+ * 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 <time.h>
+
+#include "../test/test.h"
+#include "xkbcomp-priv.h"
+#include "rules.h"
+
+#define BENCHMARK_ITERATIONS 20000
+
+int
+main(int argc, char *argv[])
+{
+ struct xkb_context *ctx;
+ struct timespec start, stop, elapsed;
+ int i;
+ struct xkb_rule_names rmlvo = {
+ "evdev", "pc105", "us,il", ",", "ctrl:nocaps,grp:menu_toggle",
+ };
+ struct xkb_component_names kccgst;
+
+ ctx = test_get_context(0);
+ assert(ctx);
+
+ xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
+ xkb_context_set_log_verbosity(ctx, 0);
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ 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);
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
+
+ elapsed.tv_sec = stop.tv_sec - start.tv_sec;
+ elapsed.tv_nsec = stop.tv_nsec - start.tv_nsec;
+ if (elapsed.tv_nsec < 0) {
+ elapsed.tv_nsec += 1000000000;
+ elapsed.tv_sec--;
+ }
+
+ fprintf(stderr, "processed %d rule files in %ld.%09lds\n",
+ BENCHMARK_ITERATIONS, elapsed.tv_sec, elapsed.tv_nsec);
+
+ xkb_context_unref(ctx);
+ return 0;
+}
diff --git a/bench/rulescomp.c b/bench/rulescomp.c
new file mode 100644
index 0000000..16f2bf5
--- /dev/null
+++ b/bench/rulescomp.c
@@ -0,0 +1,64 @@
+/*
+ * 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 <time.h>
+
+#include "../test/test.h"
+
+#define BENCHMARK_ITERATIONS 2500
+
+int
+main(int argc, char *argv[])
+{
+ struct xkb_context *ctx;
+ struct xkb_keymap *keymap;
+ struct timespec start, stop, 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);
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (i = 0; i < BENCHMARK_ITERATIONS; i++) {
+ keymap = test_compile_rules(ctx, "evdev", "evdev", "us", "", "");
+ assert(keymap);
+ xkb_keymap_unref(keymap);
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
+
+ elapsed.tv_sec = stop.tv_sec - start.tv_sec;
+ elapsed.tv_nsec = stop.tv_nsec - start.tv_nsec;
+ if (elapsed.tv_nsec < 0) {
+ elapsed.tv_nsec += 1000000000;
+ elapsed.tv_sec--;
+ }
+
+ fprintf(stderr, "compiled %d keymaps in %ld.%09lds\n",
+ BENCHMARK_ITERATIONS, elapsed.tv_sec, elapsed.tv_nsec);
+
+ xkb_context_unref(ctx);
+ return 0;
+}
diff --git a/test/.gitignore b/test/.gitignore
index 0c2354a..1e2dfb8 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -13,7 +13,6 @@ log
interactive-evdev
rmlvo-to-kccgst
print-compiled-keymap
-bench-key-proc
atom
x11
interactive-x11
diff --git a/test/rules-file.c b/test/rules-file.c
index da14e3a..e91d546 100644
--- a/test/rules-file.c
+++ b/test/rules-file.c
@@ -21,14 +21,10 @@
* DEALINGS IN THE SOFTWARE.
*/
-#include <time.h>
-
#include "test.h"
#include "xkbcomp-priv.h"
#include "rules.h"
-#define BENCHMARK_ITERATIONS 20000
-
struct test_data {
/* Rules file */
const char *rules;
@@ -88,45 +84,6 @@ test_rules(struct xkb_context *ctx, struct test_data *data)
return passed;
}
-static void
-benchmark(struct xkb_context *ctx)
-{
- struct timespec start, stop, elapsed;
- enum xkb_log_level old_level = xkb_context_get_log_level(ctx);
- int old_verb = xkb_context_get_log_verbosity(ctx);
- int i;
- struct xkb_rule_names rmlvo = {
- "evdev", "pc105", "us,il", ",", "ctrl:nocaps,grp:menu_toggle",
- };
- struct xkb_component_names kccgst;
-
- xkb_context_set_log_level(ctx, XKB_LOG_LEVEL_CRITICAL);
- xkb_context_set_log_verbosity(ctx, 0);
-
- clock_gettime(CLOCK_MONOTONIC, &start);
- 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);
- }
- clock_gettime(CLOCK_MONOTONIC, &stop);
-
- xkb_context_set_log_level(ctx, old_level);
- xkb_context_set_log_verbosity(ctx, old_verb);
-
- elapsed.tv_sec = stop.tv_sec - start.tv_sec;
- elapsed.tv_nsec = stop.tv_nsec - start.tv_nsec;
- if (elapsed.tv_nsec < 0) {
- elapsed.tv_nsec += 1000000000;
- elapsed.tv_sec--;
- }
-
- fprintf(stderr, "processed %d times in %ld.%09lds\n",
- BENCHMARK_ITERATIONS, elapsed.tv_sec, elapsed.tv_nsec);
-}
-
int
main(int argc, char *argv[])
{
@@ -135,11 +92,6 @@ main(int argc, char *argv[])
ctx = test_get_context(0);
assert(ctx);
- if (argc > 1 && streq(argv[1], "bench")) {
- benchmark(ctx);
- return 0;
- }
-
struct test_data test1 = {
.rules = "simple",
diff --git a/test/rulescomp.c b/test/rulescomp.c
index 654b275..67ffcb8 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -21,13 +21,9 @@
* DEALINGS IN THE SOFTWARE.
*/
-#include <time.h>
-
#include "evdev-scancodes.h"
#include "test.h"
-#define BENCHMARK_ITERATIONS 2500
-
static int
test_rmlvo_va(struct xkb_context *context, const char *rules,
const char *model, const char *layout,
@@ -68,21 +64,6 @@ test_rmlvo(struct xkb_context *context, const char *rules,
}
static int
-test_rmlvo_silent(struct xkb_context *context, const char *rules,
- const char *model, const char *layout,
- const char *variant, const char *options)
-{
- struct xkb_keymap *keymap;
-
- keymap = test_compile_rules(context, rules, model, layout, variant,
- options);
- if (keymap)
- xkb_keymap_unref(keymap);
-
- return keymap != NULL;
-}
-
-static int
test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
const char *layout, const char *variant, const char *options,
...)
@@ -124,36 +105,6 @@ test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
return ret;
}
-static void
-benchmark(struct xkb_context *context)
-{
- struct timespec start, stop, elapsed;
- enum xkb_log_level old_level = xkb_context_get_log_level(context);
- int old_verb = xkb_context_get_log_verbosity(context);
- int i;
-
- xkb_context_set_log_level(context, XKB_LOG_LEVEL_CRITICAL);
- xkb_context_set_log_verbosity(context, 0);
-
- clock_gettime(CLOCK_MONOTONIC, &start);
- for (i = 0; i < BENCHMARK_ITERATIONS; i++)
- assert(test_rmlvo_silent(context, "evdev", "evdev", "us", "", ""));
- clock_gettime(CLOCK_MONOTONIC, &stop);
-
- xkb_context_set_log_level(context, old_level);
- xkb_context_set_log_verbosity(context, old_verb);
-
- elapsed.tv_sec = stop.tv_sec - start.tv_sec;
- elapsed.tv_nsec = stop.tv_nsec - start.tv_nsec;
- if (elapsed.tv_nsec < 0) {
- elapsed.tv_nsec += 1000000000;
- elapsed.tv_sec--;
- }
-
- fprintf(stderr, "compiled %d keymaps in %ld.%09lds\n",
- BENCHMARK_ITERATIONS, elapsed.tv_sec, elapsed.tv_nsec);
-}
-
int
main(int argc, char *argv[])
{
@@ -161,11 +112,6 @@ main(int argc, char *argv[])
assert(ctx);
- if (argc > 1 && streq(argv[1], "bench")) {
- benchmark(ctx);
- return 0;
- }
-
#define KS(name) xkb_keysym_from_name(name, 0)
assert(test_rmlvo(ctx, "evdev", "pc105", "us,il,ru,ca", ",,,multix", "grp:alts_toggle,ctrl:nocaps,compose:rwin",
@@ -253,4 +199,5 @@ main(int argc, char *argv[])
}
xkb_context_unref(ctx);
+ return 0;
}