1 //---------------------------------------------------------------------------
5 /*#include "..\..\..\..\..\..\include\xbt\dict.h"*/
9 /* A few tests for the xbt_heap module */
11 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
13 /* This program is free software; you can redistribute it and/or modify it
14 * under the terms of the license (GNU LGPL) which comes with this package. */
20 #include "gras/virtu.h" /* time manipulation in bench */
22 #define MAX_TEST 1000000
24 int _XBT_CALL compare_double(const void *a, const void *b);
25 void test_heap_validity(int size);
26 void test_heap_mean_operation(int size);
27 void test_reset_heap(xbt_heap_t heap,int size);
30 int _XBT_CALL compare_double(const void *a, const void *b)
46 void test_heap_validity(int size)
48 xbt_heap_t heap = xbt_heap_new(size, NULL);
49 double *tab = calloc(size, sizeof(double));
52 for (i = 0; i < size; i++)
54 tab[i] = (10.0 * rand() / (RAND_MAX + 1.0));
55 xbt_heap_push(heap, NULL, tab[i]);
58 qsort(tab, size, sizeof(double), compare_double);
60 for (i = 0; i < size; i++)
62 /* printf("%lg" " ", xbt_heap_maxkey(heap)); */
63 if (xbt_heap_maxkey(heap) != tab[i])
65 fprintf(stderr, "Problem !\n");
74 printf("Validity test complete!\n");
77 void test_heap_mean_operation(int size)
79 xbt_heap_t heap = xbt_heap_new(size, NULL);
84 date = gras_os_time() * 1000000;
86 for (i = 0; i < size; i++)
87 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
89 date = gras_os_time() * 1000000 - date;
91 printf("Creation time %d size heap : %g\n", size, date);
93 date = gras_os_time() * 1000000;
95 for (j = 0; j < MAX_TEST; j++)
99 test_reset_heap(heap,size);
101 val = xbt_heap_maxkey(heap);
103 xbt_heap_push(heap, NULL, 3.0 * val);
106 date = gras_os_time() * 1000000 - date;
107 printf("Mean access time for a %d size heap : %g\n", size,date * 1.0 / (MAX_TEST + 0.0));
112 void test_reset_heap(xbt_heap_t heap,int size)
116 heap = xbt_heap_new(size, NULL);
118 for (i = 0; i < size; i++)
120 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
127 int main(int argc, char **argv)
131 for (size = 100; size < 10000; size *= 10)
133 test_heap_validity(size);
134 test_heap_mean_operation(size);
138 //---------------------------------------------------------------------------