diff options
Diffstat (limited to 'src/tc-map.c')
-rw-r--r-- | src/tc-map.c | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/tc-map.c b/src/tc-map.c index 8a22259..0037c83 100644 --- a/src/tc-map.c +++ b/src/tc-map.c @@ -1,11 +1,4 @@ -/* - * Test for libHX's maps - * Copyright Jan Engelhardt - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the WTF Public License version 2 or - * (at your option) any later version. - */ +// SPDX-License-Identifier: MIT #include "config.h" #include <errno.h> #include <math.h> @@ -25,6 +18,7 @@ #include <sys/time.h> #include "internal.h" #include "map_int.h" +#pragma GCC diagnostic ignored "-Wunused-const-variable" union HXpoly { struct HXmap *map; @@ -60,12 +54,14 @@ static void tmap_printf(const char *fmt, ...) va_end(args); } -static void tmap_time(struct timeval *tv) +static void tmap_time(struct timespec *tv) { #ifdef HAVE_SYS_RESOURCE_H struct rusage r; - if (getrusage(RUSAGE_SELF, &r) == 0) - *tv = r.ru_utime; + if (getrusage(RUSAGE_SELF, &r) == 0) { + tv->tv_sec = r.ru_utime.tv_sec; + tv->tv_nsec = r.ru_utime.tv_usec * 1000; + } #else memset(tv, 0, sizeof(*tv)); #endif @@ -134,7 +130,7 @@ static void tmap_flush(struct HXmap *map, bool verbose) static void tmap_add_speed(struct HXmap *map) { - struct timeval start, stop, delta; + struct timespec start, stop, delta; unsigned int threshold; tmap_printf("MAP test 1: Timing add operation\n"); @@ -143,20 +139,20 @@ static void tmap_add_speed(struct HXmap *map) do { tmap_add_rand(map, 1); tmap_time(&stop); - HX_timeval_sub(&delta, &stop, &start); + HX_timespec_sub(&delta, &stop, &start); } while (!(delta.tv_sec >= 1 || map->items >= 1000000)); - tmap_printf("%u elements in " HX_TIMEVAL_FMT + tmap_printf("%u elements in " HX_TIMESPEC_FMT " (plus time measurement overhead)\n", - map->items, HX_TIMEVAL_EXP(&delta)); + map->items, HX_TIMESPEC_EXP(&delta)); threshold = map->items; tmap_flush(map, false); tmap_time(&start); tmap_add_rand(map, threshold); tmap_time(&stop); - HX_timeval_sub(&delta, &stop, &start); - tmap_printf("%u elements in " HX_TIMEVAL_FMT " (w/o overhead)\n", - map->items, HX_TIMEVAL_EXP(&delta)); + HX_timespec_sub(&delta, &stop, &start); + tmap_printf("%u elements in " HX_TIMESPEC_FMT " (w/o overhead)\n", + map->items, HX_TIMESPEC_EXP(&delta)); tmap_ipop(); } @@ -167,7 +163,7 @@ static bool tmap_each_fn(const struct HXmap_node *node, void *arg) static void tmap_trav_speed(struct HXmap *map) { - struct timeval start, stop, delta, delta2; + struct timespec start, stop, delta, delta2; const struct HXmap_node *node; struct HXmap_trav *iter; @@ -178,17 +174,17 @@ static void tmap_trav_speed(struct HXmap *map) while ((node = HXmap_traverse(iter)) != NULL) ; tmap_time(&stop); - HX_timeval_sub(&delta, &stop, &start); + HX_timespec_sub(&delta, &stop, &start); HXmap_travfree(iter); - tmap_printf("Open traversal of %u nodes: " HX_TIMEVAL_FMT "s\n", - map->items, HX_TIMEVAL_EXP(&delta)); + tmap_printf("Open traversal of %u nodes: " HX_TIMESPEC_FMT "s\n", + map->items, HX_TIMESPEC_EXP(&delta)); tmap_time(&start); HXmap_qfe(map, tmap_each_fn, NULL); tmap_time(&stop); - HX_timeval_sub(&delta, &stop, &start); - tmap_printf("QFE traversal of %u nodes: " HX_TIMEVAL_FMT "s\n", - map->items, HX_TIMEVAL_EXP(&delta)); + HX_timespec_sub(&delta, &stop, &start); + tmap_printf("QFE traversal of %u nodes: " HX_TIMESPEC_FMT "s\n", + map->items, HX_TIMESPEC_EXP(&delta)); tmap_ipop(); tmap_printf("MAP test 2a: Timing lookup\n"); @@ -198,14 +194,14 @@ static void tmap_trav_speed(struct HXmap *map) while ((node = HXmap_traverse(iter)) != NULL) HXmap_find(map, node->key); tmap_time(&stop); - HX_timeval_sub(&delta2, &stop, &start); + HX_timespec_sub(&delta2, &stop, &start); HXmap_travfree(iter); /* delta2 includes traversal time */ start = delta; stop = delta2; - HX_timeval_sub(&delta, &stop, &start); - tmap_printf("Lookup of %u nodes: " HX_TIMEVAL_FMT "s\n", - map->items, HX_TIMEVAL_EXP(&delta)); + HX_timespec_sub(&delta, &stop, &start); + tmap_printf("Lookup of %u nodes: " HX_TIMESPEC_FMT "s\n", + map->items, HX_TIMESPEC_EXP(&delta)); tmap_ipop(); } @@ -222,7 +218,7 @@ static void tmap_flat(const struct HXmap *map) abort(); } for (i = 0; i < map->items; ++i) - tmap_printf("%u. %s -> %s\n", i, nodes[i].key, nodes[i].data); + tmap_printf("%u. %s -> %s\n", i, nodes[i].skey, nodes[i].sdata); tmap_ipop(); free(nodes); } |