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++) {
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++) {
59 /* printf("%lg" " ", xbt_heap_maxkey(heap)); */
60 if (xbt_heap_maxkey(heap) != tab[i]) {
61 fprintf(stderr, "Problem !\n");
70 printf("Validity test complete!\n");
73 void test_heap_mean_operation(int size)
75 xbt_heap_t heap = xbt_heap_new(size, NULL);
80 date = gras_os_time() * 1000000;
82 for (i = 0; i < size; i++)
83 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
85 date = gras_os_time() * 1000000 - date;
87 printf("Creation time %d size heap : %g\n", size, date);
89 date = gras_os_time() * 1000000;
91 for (j = 0; j < MAX_TEST; j++) {
94 test_reset_heap(heap, size);
96 val = xbt_heap_maxkey(heap);
98 xbt_heap_push(heap, NULL, 3.0 * val);
101 date = gras_os_time() * 1000000 - date;
102 printf("Mean access time for a %d size heap : %g\n", size,
103 date * 1.0 / (MAX_TEST + 0.0));
108 void test_reset_heap(xbt_heap_t heap, int size)
112 heap = xbt_heap_new(size, NULL);
114 for (i = 0; i < size; i++) {
115 xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
122 int main(int argc, char **argv)
126 for (size = 100; size < 10000; size *= 10) {
127 test_heap_validity(size);
128 test_heap_mean_operation(size);
133 //---------------------------------------------------------------------------