summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-10-12 17:13:45 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-10-12 17:13:45 +0200
commit561af7f537b80f3952ab228bcc992ad75ced280b (patch)
tree965d243582cbfaccef7a9231f5f36fac70f85662
parent1390859adc7fd084c5c546984d415e44bfc44ccd (diff)
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--.gitignore1
-rw-r--r--test/Makefile.am5
-rw-r--r--test/mtdev-matching.c141
3 files changed, 146 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 132e096..fbe141a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,4 +77,5 @@ core
77# 77#
78test/mtdev-test 78test/mtdev-test
79test/mtdev-mapgen 79test/mtdev-mapgen
80test/mtdev-matching
80patches 81patches
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 @@
1noinst_PROGRAMS = mtdev-mapgen 1noinst_PROGRAMS = mtdev-mapgen mtdev-matching
2bin_PROGRAMS = mtdev-test 2bin_PROGRAMS = mtdev-test
3 3
4INCLUDES=-I$(top_srcdir)/include/ 4INCLUDES=-I$(top_srcdir)/include/
5 5
6mtdev_mapgen_SOURCES = mtdev-mapgen.c 6mtdev_mapgen_SOURCES = mtdev-mapgen.c
7 7
8mtdev_matching_SOURCES = mtdev-matching.c
9mtdev_matching_LDFLAGS = -L$(top_builddir)/src/.libs/ -lmtdev
10
8mtdev_test_SOURCES = mtdev-test.c 11mtdev_test_SOURCES = mtdev-test.c
9mtdev_test_LDFLAGS = -lmtdev -L$(top_builddir)/src/.libs/ 12mtdev_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 @@
1/*****************************************************************************
2 *
3 * mtdev - Multitouch Protocol Translation Library (MIT license)
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include <src/match.h>
30#include <stdio.h>
31#include <time.h>
32
33#define ITS 1000000
34
35static void test1()
36{
37 int A[] = {
38 1013,
39 3030660,
40 3559354,
41 12505925,
42 19008450,
43 6946421,
44 6118613,
45 698020,
46 3021800,
47 1017,
48 37573,
49 3242018,
50 8152794,
51 1266053,
52 942941,
53 462820,
54 };
55 int index[DIM_FINGER], i;
56 mtdev_match(index, A, 4, 4);
57 for (i = 0; i < 4; i++)
58 printf("match[%d] = %d\n", i, index[i]);
59}
60
61static void test2()
62{
63 int A[] = {
64 0,
65 4534330,
66 22653552,
67 12252500,
68 685352,
69 4534330,
70 0,
71 9619317,
72 28409530,
73 6710170,
74 22653552,
75 9619317,
76 0,
77 47015292,
78 29788572,
79 2809040,
80 10428866,
81 38615920,
82 17732500,
83 719528,
84 12113945,
85 28196220,
86 46778656,
87 405,
88 14175493,
89 };
90 int index[DIM_FINGER], i;
91 mtdev_match(index, A, 5, 5);
92 for (i = 0; i < 5; i++)
93 printf("match[%d] = %d\n", i, index[i]);
94}
95
96static void speed1()
97{
98 /* column-by-column matrix */
99 int A[DIM2_FINGER];
100 int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 };
101 int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 };
102 int x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 };
103 int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 };
104 int index[DIM_FINGER];
105 int n1 = 4;
106 int n2 = 7;
107
108 int i, j;
109
110 for (i = 0; i < n1; i++) {
111 for (j = 0; j < n2; j++) {
112 A[i + n1 * j] =
113 (x1[i] - x2[j]) * (x1[i] - x2[j]) +
114 (y1[i] - y2[j]) * (y1[i] - y2[j]);
115 }
116 }
117
118 clock_t t1 = clock();
119 for (i = 0; i < ITS; i++)
120 mtdev_match(index, A, n1, n2);
121 clock_t t2 = clock();
122
123 printf("%lf matches per second\n",
124 ITS * ((float)CLOCKS_PER_SEC / (t2 - t1)));
125
126 for (i = 0; i < n1; i++)
127 printf("match[%d] = %d\n", i, index[i]);
128
129}
130
131int main(int argc, char *argv[])
132{
133 printf("test1\n");
134 test1();
135 printf("test2\n");
136 test2();
137 printf("speed1\n");
138 speed1();
139 printf("done\n");
140 return 0;
141}