-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench_remove.c
More file actions
67 lines (49 loc) · 1.63 KB
/
bench_remove.c
File metadata and controls
67 lines (49 loc) · 1.63 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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include "llpq.h" // Change all fnct names so we can also use heap?
//#include "heappq.h" // include this later
#define SAMPLES 20
int main(int argc, char *argv[]) {
int numOperations = atoi(argv[1]);
int typeOfOperation = atoi(argv[2]);
int seed = atoi(argv[3]);
double *timestamps;
timestamps = (double *) malloc(sizeof(double) * numOperations);
srand(seed); // Assign the seed to the function rand()
for(int i = 0; i < numOperations; i++) {
timestamps[i] = (rand() % 1000000) / 1000000.;
}
// for(int i = 0; i < 10; i++) {
// printf("%f\n", timestamps[i]);
// }
struct timespec t_start, t_stop; // Used for bench timings
// srand(time(NULL)); // Used for random (actual random)
long wall_sec;
long wall_nsec;
long wall_msec;
int sample = numOperations/SAMPLES;
for(int k = sample; k <= numOperations; k += sample) {
struct node *pq = newQueue(5, 0.3); // random priority insert
for(int i = 0; i < k; i++) {
insert(&pq, i, timestamps[i]); // third arg, should be t_stamp rand func
}
// printf("got here \n");
clock_gettime(CLOCK_MONOTONIC_COARSE, &t_start);
for(int i = 0; i < k; i++) {
if(!isEmpty(&pq)){
removePriorityMax(&pq);
}
}
clock_gettime(CLOCK_MONOTONIC_COARSE, &t_stop);
wall_sec = t_stop.tv_sec - t_start.tv_sec;
wall_nsec = t_stop.tv_nsec - t_start.tv_nsec;
wall_msec = (wall_sec *1000) + (wall_nsec / 1000000);
// printf("%d %ld\n", k, wall_msec);
printf("%ld\n", wall_msec);
}
return 0;
}