-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.c
216 lines (201 loc) · 5.9 KB
/
test2.c
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "lol.h"
#define DOMAIN_CNT 100
#define MAX_BUF_SIZE 16
static int REPEAT_PRINT_CNT = 500;
static int DO_NOT_USE_SYS = 1;
static void test_lol_x2()
{
char buffer[MAX_BUF_SIZE];
for (int i = 0; i < DOMAIN_CNT; i++) {
snprintf(buffer, MAX_BUF_SIZE, "%d", i);
for (int j = 0; j < REPEAT_PRINT_CNT; j++) {
lol_fatal2(buffer, "");
lol_error2(buffer, "");
lol_warn2(buffer, "");
lol_info2(buffer, "");
lol_debug2(buffer, "");
lol_trace2(buffer, "");
}
}
}
static void test_lol_x2_2(char bufs[DOMAIN_CNT][MAX_BUF_SIZE])
{
for (int i = 0; i < DOMAIN_CNT; i++) {
for (int j = 0; j < REPEAT_PRINT_CNT; j++) {
lol_fatal2(bufs[i], "");
lol_error2(bufs[i], "");
lol_warn2(bufs[i], "");
lol_info2(bufs[i], "");
lol_debug2(bufs[i], "");
lol_trace2(bufs[i], "");
}
}
}
#define test_repeat_print(d) \
for (int j = 0; j < REPEAT_PRINT_CNT; ++j) { \
lol_fatal3(d, ""); \
lol_error3(d, ""); \
lol_warn3(d, ""); \
lol_info3(d, ""); \
lol_debug3(d, ""); \
lol_trace3(d, ""); \
}
static void test_lol_x3()
{
test_repeat_print(0);
test_repeat_print(1);
test_repeat_print(2);
test_repeat_print(3);
test_repeat_print(4);
test_repeat_print(5);
test_repeat_print(6);
test_repeat_print(7);
test_repeat_print(8);
test_repeat_print(9);
test_repeat_print(10);
test_repeat_print(11);
test_repeat_print(12);
test_repeat_print(13);
test_repeat_print(14);
test_repeat_print(15);
test_repeat_print(16);
test_repeat_print(17);
test_repeat_print(18);
test_repeat_print(19);
test_repeat_print(20);
test_repeat_print(21);
test_repeat_print(22);
test_repeat_print(23);
test_repeat_print(24);
test_repeat_print(25);
test_repeat_print(26);
test_repeat_print(27);
test_repeat_print(28);
test_repeat_print(29);
test_repeat_print(30);
test_repeat_print(31);
test_repeat_print(32);
test_repeat_print(33);
test_repeat_print(34);
test_repeat_print(35);
test_repeat_print(36);
test_repeat_print(37);
test_repeat_print(38);
test_repeat_print(39);
test_repeat_print(40);
test_repeat_print(41);
test_repeat_print(42);
test_repeat_print(43);
test_repeat_print(44);
test_repeat_print(45);
test_repeat_print(46);
test_repeat_print(47);
test_repeat_print(48);
test_repeat_print(49);
test_repeat_print(50);
test_repeat_print(51);
test_repeat_print(52);
test_repeat_print(53);
test_repeat_print(54);
test_repeat_print(55);
test_repeat_print(56);
test_repeat_print(57);
test_repeat_print(58);
test_repeat_print(59);
test_repeat_print(60);
test_repeat_print(61);
test_repeat_print(62);
test_repeat_print(63);
test_repeat_print(64);
test_repeat_print(65);
test_repeat_print(66);
test_repeat_print(67);
test_repeat_print(68);
test_repeat_print(69);
test_repeat_print(70);
test_repeat_print(71);
test_repeat_print(72);
test_repeat_print(73);
test_repeat_print(74);
test_repeat_print(75);
test_repeat_print(76);
test_repeat_print(77);
test_repeat_print(78);
test_repeat_print(79);
test_repeat_print(80);
test_repeat_print(81);
test_repeat_print(82);
test_repeat_print(83);
test_repeat_print(84);
test_repeat_print(85);
test_repeat_print(86);
test_repeat_print(87);
test_repeat_print(88);
test_repeat_print(89);
test_repeat_print(90);
test_repeat_print(91);
test_repeat_print(92);
test_repeat_print(93);
test_repeat_print(94);
test_repeat_print(95);
test_repeat_print(96);
test_repeat_print(97);
test_repeat_print(98);
test_repeat_print(99);
}
static void test_init(int domain, char bufs[DOMAIN_CNT][MAX_BUF_SIZE])
{
snprintf(bufs[domain], MAX_BUF_SIZE, "%d", domain);
if (DO_NOT_USE_SYS) {
lol_add_domain(bufs[domain], LOL_NONE, NULL, LOL_NONE);
} else {
lol_add_domain(bufs[domain], domain % 6 + 1, NULL, LOL_NONE);
}
}
int main(int argc, char **argv)
{
struct timeval start, end;
double time_used1, time_used2, time_used3;
// init
char bufs[DOMAIN_CNT][MAX_BUF_SIZE];
lol_init("main", LOL_INFO, NULL, LOL_NONE);
if (argc < 4) {
// 输出帮助信息
printf("Usage: %s [TEST_LOL_X2] [TEST_LOL_X2_2] [TEST_LOL_X3] "
"[REPEAT_PRINT_CNT] "
"[DO_NOT_USE_SYS]\n",
argv[0]);
return 1;
}
int test1 = argc > 1 && atoi(argv[1]);
int test2 = argc > 2 && atoi(argv[2]);
int test3 = argc > 3 && atoi(argv[3]);
if (argc > 4) REPEAT_PRINT_CNT = atoi(argv[4]);
if (argc > 5) DO_NOT_USE_SYS = atoi(argv[5]);
for (int i = 0; i < DOMAIN_CNT; i++) {
test_init(i, bufs);
}
gettimeofday(&start, NULL);
if (test1) test_lol_x2();
gettimeofday(&end, NULL);
time_used1 =
(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
gettimeofday(&start, NULL);
if (test2) test_lol_x2_2(bufs);
gettimeofday(&end, NULL);
time_used2 =
(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
gettimeofday(&start, NULL);
if (test3) test_lol_x3();
gettimeofday(&end, NULL);
time_used3 =
(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
printf("test_lol_v2: Time used: %f seconds\n", time_used1);
printf("test_lol_v2_2: Time used: %f seconds\n", time_used2);
printf("test_lol_v3: Time used: %f seconds\n", time_used3);
lol_fini();
return 0;
}