]> git.sur5r.net Git - glabels/blob - glabels2/qrencode-3.1.0/tests/prof_qrencode.c
509a739e2a5cec7c7a22f98371b2eaea8c1a5dc6
[glabels] / glabels2 / qrencode-3.1.0 / tests / prof_qrencode.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <time.h>
5 #include <errno.h>
6 #include "../qrencode.h"
7 #include "../qrspec.h"
8 #include "../rscode.h"
9
10 struct timeval tv;
11 void timerStart(const char *str)
12 {
13         printf("%s: START\n", str);
14         gettimeofday(&tv, NULL);
15 }
16
17 void timerStop(void)
18 {
19         struct timeval tc;
20
21         gettimeofday(&tc, NULL);
22         printf("STOP: %ld msec\n", (tc.tv_sec - tv.tv_sec) * 1000
23                         + (tc.tv_usec - tv.tv_usec) / 1000);
24 }
25
26 void prof_ver1to10(void)
27 {
28         QRcode *code;
29         int i;
30         int version;
31         static const char *data = "This is test.";
32
33         timerStart("Version 1 - 10 (500 symbols for each)");
34         for(i=0; i<500; i++) {
35                 for(version = 0; version < 11; version++) {
36                         code = QRcode_encodeString(data, version, QR_ECLEVEL_L, QR_MODE_8, 0);
37                         if(code == NULL) {
38                                 perror("Failed to encode:");
39                         } else {
40                                 QRcode_free(code);
41                         }
42                 }
43         }
44         timerStop();
45 }
46
47 void prof_ver31to40(void)
48 {
49         QRcode *code;
50         int i;
51         int version;
52         static const char *data = "This is test.";
53
54         timerStart("Version 31 - 40 (50 symbols for each)");
55         for(i=0; i<50; i++) {
56                 for(version = 31; version < 41; version++) {
57                         code = QRcode_encodeString(data, version, QR_ECLEVEL_L, QR_MODE_8, 0);
58                         if(code == NULL) {
59                                 perror("Failed to encode:");
60                         } else {
61                                 QRcode_free(code);
62                         }
63                 }
64         }
65         timerStop();
66 }
67
68 int main()
69 {
70         prof_ver1to10();
71         prof_ver31to40();
72
73         QRspec_clearCache();
74         free_rs_cache();
75
76         return 0;
77 }