-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.c
55 lines (45 loc) · 1.51 KB
/
benchmark.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
#include "euler_tour_tree.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Reads in a file created by benchmark_gen, performs the listed operations,
// and outputs the total time taken, in microseconds
void benchmark_ops() {
int ops, n;
scanf("%d, %d\n", &ops, &n);
int* op_array = malloc(sizeof(int) * ops);
int* i_array = malloc(sizeof(int) * ops);
int* j_array = malloc(sizeof(int) * ops);
for (int line = 0; line < ops; line++) {
scanf("%d, %d, %d\n", op_array + line, i_array + line, j_array + line);
}
clock_t start_time = clock();
for (int round = 0; round < 10; round ++) {
EulerTourTree* tree = make_euler_tour_tree(n);
for (int line = 0; line < ops; line++) {
int op = op_array[line];
int i = i_array[line];
int j = j_array[line];
if (op == 0) {
connectivity(tree, i, j);
} else if (op == 1) {
link(tree, i, j);
} else if (op == 2) {
cut(tree, i);
} else if (op == 3) {
subtree_aggregate_min(tree, i);
} else if (op == 4) {
point_update(tree, i, j);
} else if (op == 5) {
subtree_update(tree, i, j);
}
}
destroy_euler_tour_tree(tree);
}
clock_t end_time = clock();
printf("%f %d %d\n", ((double) (end_time-start_time))*1e6/CLOCKS_PER_SEC/ops, ops, n);
}
int main() {
benchmark_ops();
}