File: pthread_qrencode.c

package info (click to toggle)
qrencode 4.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,992 kB
  • sloc: ansic: 11,778; sh: 4,926; makefile: 112
file content (135 lines) | stat: -rw-r--r-- 2,553 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <stdlib.h>
#if HAVE_CONFIG_H
#include "../config.h"
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <pthread.h>
#include <errno.h>
#include "../qrencode.h"

#define THREADS (10)

static pthread_t threads[THREADS];

#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
static LARGE_INTEGER startTime;
static LARGE_INTEGER frequency = { .QuadPart = 0 };
#else
static struct timeval tv;
#endif

static void timerStart(const char *str)
{
	printf("%s: START\n", str);
#ifdef _MSC_VER
	(void) QueryPerformanceCounter(&startTime);
#else
	gettimeofday(&tv, NULL);
#endif
}

static void timerStop(void)
{
#ifdef _MSC_VER
	LARGE_INTEGER endTime, elapsed;
	(void) QueryPerformanceCounter(&endTime);
	if (frequency.QuadPart == 0) {
		(void) QueryPerformanceFrequency(&frequency);
	}

	elapsed.QuadPart = endTime.QuadPart - startTime.QuadPart;
	elapsed.QuadPart *= 1000;
	elapsed.QuadPart /= frequency.QuadPart;

	printf("STOP: %lld msec\n", elapsed.QuadPart);
#else
	struct timeval tc;

	gettimeofday(&tc, NULL);
	printf("STOP: %ld msec\n", (tc.tv_sec - tv.tv_sec) * 1000
			+ (tc.tv_usec - tv.tv_usec) / 1000);
#endif
}

static void *encode_ver1to10(void *arg)
{
	QRcode *code;
	int i;
	int version;
	static const char *data = "This is test.";

	for(i=0; i<500; i++) {
		for(version = 0; version < 11; version++) {
			code = QRcode_encodeString(data, version, QR_ECLEVEL_L, QR_MODE_8, 0);
			if(code == NULL) {
				perror("Failed to encode:");
			} else {
				QRcode_free(code);
			}
		}
	}

	return NULL;
}

static void prof_ver1to10(void)
{
	int i;

	timerStart("Version 1 - 10 (500 symbols for each)");
	for(i=0; i<THREADS; i++) {
		pthread_create(&threads[i], NULL, encode_ver1to10, NULL);
	}
	for(i=0; i<THREADS; i++) {
		pthread_join(threads[i], NULL);
	}
	timerStop();
}

static void *encode_ver31to40(void *arg)
{
	QRcode *code;
	int i;
	int version;
	static const char *data = "This is test.";

	for(i=0; i<50; i++) {
		for(version = 31; version < 41; version++) {
			code = QRcode_encodeString(data, version, QR_ECLEVEL_L, QR_MODE_8, 0);
			if(code == NULL) {
				perror("Failed to encode:");
			} else {
				QRcode_free(code);
			}
		}
	}

	return NULL;
}

static void prof_ver31to40(void)
{
	int i;

	timerStart("Version 31 - 40 (50 symbols for each)");
	for(i=0; i<THREADS; i++) {
		pthread_create(&threads[i], NULL, encode_ver31to40, NULL);
	}
	for(i=0; i<THREADS; i++) {
		pthread_join(threads[i], NULL);
	}
	timerStop();
}

int main()
{
	prof_ver1to10();
	prof_ver31to40();

	return 0;
}