1 /* A few tests for the xbt_heap module */
3 /* Authors: Arnaud Legrand */
5 /* This program is free software; you can redistribute it and/or modify it
6 under the terms of the license (GNU LGPL) which comes with this package. */
13 #define MAX_TEST 1000000
20 gettimeofday(&start, NULL);
22 return (start.tv_sec * 1000000 + start.tv_usec);
25 int compare_xbt_heap_float_t(const void *a, const void *b);
26 void test_heap_validity(int size);
27 void test_heap_mean_operation(int size);
29 int compare_xbt_heap_float_t(const void *a, const void *b)
31 xbt_heap_float_t pa, pb;
33 pa = *((xbt_heap_float_t *) a);
34 pb = *((xbt_heap_float_t *) b);
43 void test_heap_validity(int size)
45 xbt_heap_t heap = xbt_heap_new(size, NULL);
46 xbt_heap_float_t *tab = calloc(size, sizeof(xbt_heap_float_t));
49 for (i = 0; i < size; i++) {
50 tab[i] = (10.0 * rand() / (RAND_MAX + 1.0));
51 xbt_heap_push(heap, NULL, tab[i]);
54 qsort(tab, size, sizeof(xbt_heap_float_t), compare_xbt_heap_float_t);
56 for (i = 0; i < size; i++) {
57 /* printf(XBT_HEAP_FLOAT_T " ", xbt_heap_maxkey(heap)); */
58 if (xbt_heap_maxkey(heap) != tab[i]) {
59 fprintf(stderr, "Problem !\n");
66 printf("Validity test complete!\n");
69 void test_heap_mean_operation(int size)
71 xbt_heap_t heap = xbt_heap_new(size, NULL);
77 for (i = 0; i < size; i++)
78 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
79 date = us_time() - date;
80 printf("Creation time %d size heap : %g\n", size, 0.0 + date);
83 for (j = 0; j < MAX_TEST; j++) {
84 val = xbt_heap_maxkey(heap);
86 xbt_heap_push(heap, NULL, 3.0 * val);
88 date = us_time() - date;
89 printf("Mean access time for a %d size heap : %g\n", size,
90 date * 1.0 / (MAX_TEST + 0.0));
95 int main(int argc, char **argv)
98 for (size = 100; size < 10000; size *= 10) {
99 test_heap_validity(size);
100 test_heap_mean_operation(size);