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 4000000
34 static const int n1 = 4;
35 static const int n2 = 4;
36
test1()37 static void test1()
38 {
39 int A[] = {
40 1013,
41 3030660,
42 3559354,
43 12505925,
44 19008450,
45 6946421,
46 6118613,
47 698020,
48 3021800,
49 1017,
50 37573,
51 3242018,
52 8152794,
53 1266053,
54 942941,
55 462820,
56 };
57 int index[DIM_FINGER], i;
58 mtdev_match(index, A, 4, 4);
59 for (i = 0; i < 4; i++)
60 printf("match[%d] = %d\n", i, index[i]);
61 }
62
test2()63 static void test2()
64 {
65 int A[] = {
66 0,
67 4534330,
68 22653552,
69 12252500,
70 685352,
71 4534330,
72 0,
73 9619317,
74 28409530,
75 6710170,
76 22653552,
77 9619317,
78 0,
79 47015292,
80 29788572,
81 2809040,
82 10428866,
83 38615920,
84 17732500,
85 719528,
86 12113945,
87 28196220,
88 46778656,
89 405,
90 14175493,
91 };
92 int index[DIM_FINGER], i;
93 mtdev_match(index, A, 5, 5);
94 for (i = 0; i < 5; i++)
95 printf("match[%d] = %d\n", i, index[i]);
96 }
97
speed1()98 static void speed1()
99 {
100 /* column-by-column matrix */
101 int A[DIM2_FINGER];
102 int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 };
103 int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 };
104 int x2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 };
105 int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 };
106 int index[DIM_FINGER];
107 int i, j, k;
108
109 clock_t t1 = clock();
110 for (k = 0; k < ITS; k++) {
111 for (i = 0; i < n1; i++) {
112 for (j = 0; j < n2; j++) {
113 A[i + n1 * j] =
114 (x1[i] - x2[j]) * (x1[i] - x2[j]) +
115 (y1[i] - y2[j]) * (y1[i] - y2[j]);
116 }
117 }
118 mtdev_match(index, A, n1, n2);
119 }
120 clock_t t2 = clock();
121
122 printf("%lf matches per second\n",
123 ITS * ((float)CLOCKS_PER_SEC / (t2 - t1)));
124
125 for (i = 0; i < n1; i++)
126 printf("match[%d] = %d\n", i, index[i]);
127
128 }
129
speed2()130 static void speed2()
131 {
132 struct trk_coord p1[] = {
133 { 1, 1 },
134 { 5, 5 },
135 { 2, 2 },
136 { 3, 3 },
137 { 4, 4 },
138 };
139 struct trk_coord p2[] = {
140 { 1, 1 },
141 { 3, 3 },
142 { 2, 2 },
143 { 4, 4 },
144 { 5, 5 },
145 };
146 const unsigned char *p;
147 int i;
148
149 clock_t t1 = clock();
150 for (i = 0; i < ITS; i++)
151 p = mtdev_match_four(p1, n1, p2, n2);
152 clock_t t2 = clock();
153
154 printf("%lf matches per second\n",
155 ITS * ((float)CLOCKS_PER_SEC / (t2 - t1)));
156
157 for (i = 0; i < n2; i++)
158 printf("match[%d] = %d\n", i, p[i]);
159
160 }
161
main(int argc,char * argv[])162 int main(int argc, char *argv[])
163 {
164 printf("test1\n");
165 test1();
166 printf("test2\n");
167 test2();
168 printf("speed1\n");
169 speed1();
170 printf("speed2\n");
171 speed2();
172 printf("done\n");
173 return 0;
174 }
175