1 //---------------------------------------------------------------------------
5 /*#include "..\..\..\..\..\..\include\xbt\dict.h"*/
7 /* A few tests for the xbt_heap module */
9 /* Copyright (c) 2006, 2010. The SimGrid Team.
10 * All rights reserved. */
12 /* This program is free software; you can redistribute it and/or modify it
13 * under the terms of the license (GNU LGPL) which comes with this package. */
19 #include "gras/virtu.h" /* time manipulation in bench */
21 #define MAX_TEST 1000000
23 int _XBT_CALL compare_double(const void *a, const void *b);
24 void test_heap_validity(int size);
25 void test_heap_mean_operation(int size);
26 void test_reset_heap(xbt_heap_t heap,int size);
29 int _XBT_CALL compare_double(const void *a, const void *b)
45 void test_heap_validity(int size)
47 xbt_heap_t heap = xbt_heap_new(size, NULL);
48 double *tab = calloc(size, sizeof(double));
51 for (i = 0; i < size; i++)
53 tab[i] = (10.0 * rand() / (RAND_MAX + 1.0));
54 xbt_heap_push(heap, NULL, tab[i]);
57 qsort(tab, size, sizeof(double), compare_double);
59 for (i = 0; i < size; i++)
61 /* printf("%lg" " ", xbt_heap_maxkey(heap)); */
62 if (xbt_heap_maxkey(heap) != tab[i])
64 fprintf(stderr, "Problem !\n");
73 printf("Validity test complete!\n");
76 void test_heap_mean_operation(int size)
78 xbt_heap_t heap = xbt_heap_new(size, NULL);
83 date = gras_os_time() * 1000000;
85 for (i = 0; i < size; i++)
86 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
88 date = gras_os_time() * 1000000 - date;
90 printf("Creation time %d size heap : %g\n", size, date);
92 date = gras_os_time() * 1000000;
94 for (j = 0; j < MAX_TEST; j++)
98 test_reset_heap(heap,size);
100 val = xbt_heap_maxkey(heap);
102 xbt_heap_push(heap, NULL, 3.0 * val);
105 date = gras_os_time() * 1000000 - date;
106 printf("Mean access time for a %d size heap : %g\n", size,date * 1.0 / (MAX_TEST + 0.0));
111 void test_reset_heap(xbt_heap_t heap,int size)
115 heap = xbt_heap_new(size, NULL);
117 for (i = 0; i < size; i++)
119 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
126 int main(int argc, char **argv)
130 for (size = 100; size < 10000; size *= 10)
132 test_heap_validity(size);
133 test_heap_mean_operation(size);
137 //---------------------------------------------------------------------------