#include #include #include #include #include "Pq.h" #define BENCHMARK_SIZE 20000 int *genItems(int numItems); void shuffle(int *arr, int size); int main(void) { int n = BENCHMARK_SIZE; int *items = genItems(n); Pq pq = PqNew(); clock_t start; clock_t end; start = clock(); for (int i = 0; i < n; i++) { PqInsert(pq, items[i], items[i]); } end = clock(); printf("Insertion of %d items took %lf seconds\n", n, (double)(end - start) / CLOCKS_PER_SEC); start = clock(); for (int i = n; i >= 1; i--) { assert(PqDelete(pq) == i); } end = clock(); printf("Deletion of %d items took %lf seconds\n", n, (double)(end - start) / CLOCKS_PER_SEC); PqFree(pq); free(items); } int *genItems(int numItems) { int *items = malloc(numItems * sizeof(int)); if (items == NULL) { fprintf(stderr, "error: out of memory\n"); exit(EXIT_FAILURE); } for (int i = 0; i < numItems; i++) { items[i] = i + 1; } shuffle(items, numItems); return items; } void shuffle(int *arr, int size) { for (int i = 1; i < size; i++) { int j = rand() % (i + 1); int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } }