diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-11-07 18:04:46 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-11-07 18:04:46 +0100 |
| commit | 67fdae132708889ed89e302bd63a5cb91b2c75a7 (patch) | |
| tree | 29e6b2989ab5180eece929ad7a12def515e24259 /test/mtdev-matching.c | |
| parent | 868f53c8a5684524bc6b1e7cd39aabed56fad9df (diff) | |
Add and test a simple kernel matcher
This matcher is for up to four fingers, and has these properties:
* Approximately 1.4 times faster at 4 fingers
* Approximately 4.0 times faster at 2 fingers
* Roughly 100 lines of code
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'test/mtdev-matching.c')
| -rw-r--r-- | test/mtdev-matching.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/test/mtdev-matching.c b/test/mtdev-matching.c index dc68994..799429f 100644 --- a/test/mtdev-matching.c +++ b/test/mtdev-matching.c | |||
| @@ -30,7 +30,9 @@ | |||
| 30 | #include <stdio.h> | 30 | #include <stdio.h> |
| 31 | #include <time.h> | 31 | #include <time.h> |
| 32 | 32 | ||
| 33 | #define ITS 1000000 | 33 | #define ITS 4000000 |
| 34 | const int n1 = 4; | ||
| 35 | const int n2 = 4; | ||
| 34 | 36 | ||
| 35 | static void test1() | 37 | static void test1() |
| 36 | { | 38 | { |
| @@ -99,32 +101,61 @@ static void speed1() | |||
| 99 | int A[DIM2_FINGER]; | 101 | int A[DIM2_FINGER]; |
| 100 | int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 }; | 102 | 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 }; | 103 | 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 }; | 104 | int x2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; |
| 103 | int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; | 105 | int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; |
| 104 | int index[DIM_FINGER]; | 106 | int index[DIM_FINGER]; |
| 105 | int n1 = 4; | 107 | int i, j, k; |
| 106 | int n2 = 7; | ||
| 107 | 108 | ||
| 108 | int i, j; | 109 | clock_t t1 = clock(); |
| 109 | 110 | for (k = 0; k < ITS; k++) { | |
| 110 | for (i = 0; i < n1; i++) { | 111 | for (i = 0; i < n1; i++) { |
| 111 | for (j = 0; j < n2; j++) { | 112 | for (j = 0; j < n2; j++) { |
| 112 | A[i + n1 * j] = | 113 | A[i + n1 * j] = |
| 113 | (x1[i] - x2[j]) * (x1[i] - x2[j]) + | 114 | (x1[i] - x2[j]) * (x1[i] - x2[j]) + |
| 114 | (y1[i] - y2[j]) * (y1[i] - y2[j]); | 115 | (y1[i] - y2[j]) * (y1[i] - y2[j]); |
| 116 | } | ||
| 115 | } | 117 | } |
| 118 | mtdev_match(index, A, n1, n2); | ||
| 116 | } | 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 | |||
| 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; | ||
| 117 | 148 | ||
| 118 | clock_t t1 = clock(); | 149 | clock_t t1 = clock(); |
| 119 | for (i = 0; i < ITS; i++) | 150 | for (i = 0; i < ITS; i++) |
| 120 | mtdev_match(index, A, n1, n2); | 151 | p = mtdev_match_four(p1, n1, p2, n2); |
| 121 | clock_t t2 = clock(); | 152 | clock_t t2 = clock(); |
| 122 | 153 | ||
| 123 | printf("%lf matches per second\n", | 154 | printf("%lf matches per second\n", |
| 124 | ITS * ((float)CLOCKS_PER_SEC / (t2 - t1))); | 155 | ITS * ((float)CLOCKS_PER_SEC / (t2 - t1))); |
| 125 | 156 | ||
| 126 | for (i = 0; i < n1; i++) | 157 | for (i = 0; i < n2; i++) |
| 127 | printf("match[%d] = %d\n", i, index[i]); | 158 | printf("match[%d] = %d\n", i, p[i]); |
| 128 | 159 | ||
| 129 | } | 160 | } |
| 130 | 161 | ||
| @@ -136,6 +167,8 @@ int main(int argc, char *argv[]) | |||
| 136 | test2(); | 167 | test2(); |
| 137 | printf("speed1\n"); | 168 | printf("speed1\n"); |
| 138 | speed1(); | 169 | speed1(); |
| 170 | printf("speed2\n"); | ||
| 171 | speed2(); | ||
| 139 | printf("done\n"); | 172 | printf("done\n"); |
| 140 | return 0; | 173 | return 0; |
| 141 | } | 174 | } |
