1 //---------------------------------------------------------------------------
5 /*#include "..\..\..\..\..\..\include\xbt\dict.h"*/
7 /* A few tests for the xbt_heap module */
9 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
11 /* This program is free software; you can redistribute it and/or modify it
12 * under the terms of the license (GNU LGPL) which comes with this package. */
18 #include "gras/virtu.h" /* time manipulation in bench */
20 #define MAX_TEST 1000000
22 int _XBT_CALL compare_double(const void *a, const void *b);
23 void test_heap_validity(int size);
24 void test_heap_mean_operation(int size);
25 void test_reset_heap(xbt_heap_t heap,int size);
28 int _XBT_CALL compare_double(const void *a, const void *b)
44 void test_heap_validity(int size)
46 xbt_heap_t heap = xbt_heap_new(size, NULL);
47 double *tab = calloc(size, sizeof(double));
50 for (i = 0; i < size; i++)
52 tab[i] = (10.0 * rand() / (RAND_MAX + 1.0));
53 xbt_heap_push(heap, NULL, tab[i]);
56 qsort(tab, size, sizeof(double), compare_double);
58 for (i = 0; i < size; i++)
60 /* printf("%lg" " ", xbt_heap_maxkey(heap)); */
61 if (xbt_heap_maxkey(heap) != tab[i])
63 fprintf(stderr, "Problem !\n");
72 printf("Validity test complete!\n");
75 void test_heap_mean_operation(int size)
77 xbt_heap_t heap = xbt_heap_new(size, NULL);
82 date = gras_os_time() * 1000000;
84 for (i = 0; i < size; i++)
85 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
87 date = gras_os_time() * 1000000 - date;
89 printf("Creation time %d size heap : %g\n", size, date);
91 date = gras_os_time() * 1000000;
93 for (j = 0; j < MAX_TEST; j++)
97 test_reset_heap(heap,size);
99 val = xbt_heap_maxkey(heap);
101 xbt_heap_push(heap, NULL, 3.0 * val);
104 date = gras_os_time() * 1000000 - date;
105 printf("Mean access time for a %d size heap : %g\n", size,date * 1.0 / (MAX_TEST + 0.0));
110 void test_reset_heap(xbt_heap_t heap,int size)
114 heap = xbt_heap_new(size, NULL);
116 for (i = 0; i < size; i++)
118 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
125 int main(int argc, char **argv)
129 for (size = 100; size < 10000; size *= 10)
131 test_heap_validity(size);
132 test_heap_mean_operation(size);
136 //---------------------------------------------------------------------------