diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2010-10-12 17:13:45 +0200 |
---|---|---|
committer | Henrik Rydberg <rydberg@euromail.se> | 2010-10-12 17:13:45 +0200 |
commit | 561af7f537b80f3952ab228bcc992ad75ced280b (patch) | |
tree | 965d243582cbfaccef7a9231f5f36fac70f85662 | |
parent | 1390859adc7fd084c5c546984d415e44bfc44ccd (diff) | |
download | mtdev-git-561af7f537b80f3952ab228bcc992ad75ced280b.tar.gz |
Add mtdev-matching test program
Measures matching speed and provides some historically difficult
test cases.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 5 | ||||
-rw-r--r-- | test/mtdev-matching.c | 141 |
3 files changed, 146 insertions, 1 deletions
@@ -77,4 +77,5 @@ core # test/mtdev-test test/mtdev-mapgen +test/mtdev-matching patches diff --git a/test/Makefile.am b/test/Makefile.am index b1be019..12df79a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,9 +1,12 @@ -noinst_PROGRAMS = mtdev-mapgen +noinst_PROGRAMS = mtdev-mapgen mtdev-matching bin_PROGRAMS = mtdev-test INCLUDES=-I$(top_srcdir)/include/ mtdev_mapgen_SOURCES = mtdev-mapgen.c +mtdev_matching_SOURCES = mtdev-matching.c +mtdev_matching_LDFLAGS = -L$(top_builddir)/src/.libs/ -lmtdev + mtdev_test_SOURCES = mtdev-test.c mtdev_test_LDFLAGS = -lmtdev -L$(top_builddir)/src/.libs/ diff --git a/test/mtdev-matching.c b/test/mtdev-matching.c new file mode 100644 index 0000000..dc68994 --- /dev/null +++ b/test/mtdev-matching.c @@ -0,0 +1,141 @@ +/***************************************************************************** + * + * mtdev - Multitouch Protocol Translation Library (MIT license) + * + * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> + * Copyright (C) 2010 Canonical Ltd. + * + * 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 <src/match.h> +#include <stdio.h> +#include <time.h> + +#define ITS 1000000 + +static void test1() +{ + int A[] = { + 1013, + 3030660, + 3559354, + 12505925, + 19008450, + 6946421, + 6118613, + 698020, + 3021800, + 1017, + 37573, + 3242018, + 8152794, + 1266053, + 942941, + 462820, + }; + int index[DIM_FINGER], i; + mtdev_match(index, A, 4, 4); + for (i = 0; i < 4; i++) + printf("match[%d] = %d\n", i, index[i]); +} + +static void test2() +{ + int A[] = { + 0, + 4534330, + 22653552, + 12252500, + 685352, + 4534330, + 0, + 9619317, + 28409530, + 6710170, + 22653552, + 9619317, + 0, + 47015292, + 29788572, + 2809040, + 10428866, + 38615920, + 17732500, + 719528, + 12113945, + 28196220, + 46778656, + 405, + 14175493, + }; + int index[DIM_FINGER], i; + mtdev_match(index, A, 5, 5); + for (i = 0; i < 5; i++) + printf("match[%d] = %d\n", i, index[i]); +} + +static void speed1() +{ + /* column-by-column matrix */ + int A[DIM2_FINGER]; + int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 }; + int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 }; + int x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 }; + int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; + int index[DIM_FINGER]; + int n1 = 4; + int n2 = 7; + + int i, j; + + for (i = 0; i < n1; i++) { + for (j = 0; j < n2; j++) { + A[i + n1 * j] = + (x1[i] - x2[j]) * (x1[i] - x2[j]) + + (y1[i] - y2[j]) * (y1[i] - y2[j]); + } + } + + clock_t t1 = clock(); + for (i = 0; i < ITS; i++) + mtdev_match(index, A, n1, n2); + clock_t t2 = clock(); + + printf("%lf matches per second\n", + ITS * ((float)CLOCKS_PER_SEC / (t2 - t1))); + + for (i = 0; i < n1; i++) + printf("match[%d] = %d\n", i, index[i]); + +} + +int main(int argc, char *argv[]) +{ + printf("test1\n"); + test1(); + printf("test2\n"); + test2(); + printf("speed1\n"); + speed1(); + printf("done\n"); + return 0; +} |