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
|
#include <time.h>
#include <stdio.h>
#include "ini.h"
ini_parser parser;
#define TEST_FILE "test.ini"
__attribute__((optimize("unroll-loops")))
double run_bench(int count) {
clock_t start, end;
start = clock();
for (int i = 0; i < count; i++) {
get_ini_value(&parser, "Test1", "Test");
get_ini_value(&parser, "Test1", "String");
get_ini_value(&parser, "Test1", "Int");
get_ini_value(&parser, "Test2", "Test");
get_ini_value(&parser, "Test2", "String");
get_ini_value(&parser, "Test2", "Int");
}
end = clock();
return ((double) (end - start)) / CLOCKS_PER_SEC;
}
int main(void) {
if (!load_ini_file(&parser, TEST_FILE)) {
printf("failed to load file\n");
}
printf("Test results:\n");
printf("'%s'\n", get_ini_value(&parser, "Test1", "Test"));
printf("'%s'\n", get_ini_value(&parser, "Test1", "String"));
printf("'%s'\n", get_ini_value(&parser, "Test1", "Int"));
printf("'%s'\n", get_ini_value(&parser, "Test2", "Test"));
printf("'%s'\n", get_ini_value(&parser, "Test2", "String"));
printf("'%s'\n", get_ini_value(&parser, "Test2", "Int"));
printf("Test on file '%s' took %f seconds for 60 queries\n", TEST_FILE, run_bench(10));
printf("Test on file '%s' took %f seconds for 600 queries\n", TEST_FILE, run_bench(100));
printf("Test on file '%s' took %f seconds for 6000 queries\n", TEST_FILE, run_bench(1000));
printf("Test on file '%s' took %f seconds for 60000 queries\n", TEST_FILE, run_bench(10000));
printf("Test on file '%s' took %f seconds for 600000 queries\n", TEST_FILE, run_bench(100000));
unload_ini_file(&parser);
return 0;
}
|