-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.c
More file actions
44 lines (34 loc) · 893 Bytes
/
bench.c
File metadata and controls
44 lines (34 loc) · 893 Bytes
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
#include "array.h"
#include "bench.h"
#define ITERS 1000000
#define WARMUP 100
#define BATCH 100
volatile int sink = 0;
int main(void) {
int* numbers;
BENCH("Array alloc+free", ITERS, BATCH, WARMUP, {
ARRAY(numbers, 100);
numbers[0] = 1;
sink += numbers[0];
ARRAY_FREE(numbers);
});
ARRAY(numbers, 10000);
BENCH("Array append (no resize)", ITERS, 1, WARMUP, {
ARRAY_CLEAR(numbers);
for (int i = 0; i < 10000; ++i) {
ARRAY_APPEND(numbers, i);
sink += numbers[i];
}
});
BENCH("Array append (resize)", ITERS, 1, WARMUP, {
ARRAY_FREE(numbers);
ARRAY(numbers, 10);
for (int i = 0; i < 10000; ++i) {
ARRAY_APPEND(numbers, i);
sink += numbers[i];
}
});
ARRAY_FREE(numbers);
(void)sink;
exit(EXIT_SUCCESS);
}