forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.c
More file actions
80 lines (56 loc) · 1.58 KB
/
Copy pathdiff.c
File metadata and controls
80 lines (56 loc) · 1.58 KB
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
#include <benchmarks.h>
#include <kdb.h>
#include <kdbdiff.h>
int main (void)
{
int runs = 100;
int numKeys = 1000;
KeySet * new = ksNew (0, KS_END);
KeySet * old = ksNew (0, KS_END);
char nameBuffer[100] = "";
char valueBuffer[50] = "";
for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/a/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);
Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);
ksAppendKey (new, k);
ksAppendKey (old, k);
}
for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/a/%d", i * 2 + 1);
snprintf (valueBuffer, 49, "%d", i);
ksAppendKey (new, keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END));
snprintf (valueBuffer, 49, "%d modified", i);
ksAppendKey (old, keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END));
}
for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/b/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);
Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);
ksAppendKey (new, k);
}
for (int i = 0; i < numKeys; i++)
{
snprintf (nameBuffer, 99, "system:/c/%d", i * 2);
snprintf (valueBuffer, 49, "%d", i);
Key * k = keyNew (nameBuffer, KEY_VALUE, valueBuffer, KEY_END);
ksAppendKey (old, k);
}
int sum = 0;
for (int i = 0; i < runs; i++)
{
timeInit ();
ElektraDiff * diff = elektraDiffCalculate (new, old, NULL);
int us = timeGetDiffMicroseconds ();
sum += us;
printf ("%d us\n", us);
elektraDiffDel (diff);
}
printf ("Average: %.2f", (double) sum / runs);
ksDel (new);
ksDel (old);
return 0;
}