X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhtable%2Ftools%2Fstringspeed.c;h=c6ca10f523aed5f9c7cefc71c55606a744fbf5cd;hp=53ac4da650a377a0f0b27e8f74f83b2828664ac0;hb=HEAD;hpb=95757f0e9d979e7c653e9b53bb640deb4f0ea1f9 diff --git a/ccan/htable/tools/stringspeed.c b/ccan/htable/tools/stringspeed.c index 53ac4da6..c6ca10f5 100644 --- a/ccan/htable/tools/stringspeed.c +++ b/ccan/htable/tools/stringspeed.c @@ -1,9 +1,9 @@ /* Simple speed tests for a hash of strings. */ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -34,44 +34,38 @@ static bool cmp(const char *obj, const char *key) HTABLE_DEFINE_TYPE(char, strkey, hash_str, cmp, htable_str); /* Nanoseconds per operation */ -static size_t normalize(const struct timeval *start, - const struct timeval *stop, +static size_t normalize(const struct timeabs *start, + const struct timeabs *stop, unsigned int num) { - struct timeval diff; - - timersub(stop, start, &diff); - - /* Floating point is more accurate here. */ - return (double)(diff.tv_sec * 1000000 + diff.tv_usec) - / num * 1000; + return time_to_nsec(time_divide(time_between(*stop, *start), num)); } int main(int argc, char *argv[]) { size_t i, j, num; - struct timeval start, stop; + struct timeabs start, stop; struct htable_str ht; char **words, **misswords; - words = strsplit(NULL, grab_file(NULL, - argv[1] ? argv[1] : "/usr/share/dict/words", - NULL), "\n"); + words = tal_strsplit(NULL, grab_file(NULL, + argv[1] ? argv[1] : "/usr/share/dict/words"), "\n", + STR_NO_EMPTY); htable_str_init(&ht); - num = talloc_array_length(words) - 1; + num = tal_count(words) - 1; /* Note that on my system, num is just > 98304, where we double! */ printf("%zu words\n", num); /* Append and prepend last char for miss testing. */ - misswords = talloc_array(words, char *, num); + misswords = tal_arr(words, char *, num); for (i = 0; i < num; i++) { char lastc; if (strlen(words[i])) lastc = words[i][strlen(words[i])-1]; else lastc = 'z'; - misswords[i] = talloc_asprintf(misswords, "%c%s%c%c", - lastc, words[i], lastc, lastc); + misswords[i] = tal_fmt(misswords, "%c%s%c%c", + lastc, words[i], lastc, lastc); } printf("#01: Initial insert: ");