X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fhtable%2Ftools%2Fhsearchspeed.c;h=88280114f3842f432170782b49b801146c035495;hb=b3cc8ae7c2fe35cf20bd0bac211658c0ecbdbdae;hp=ea1a3f5c4e83960ea057087a8035075bb9bee750;hpb=95757f0e9d979e7c653e9b53bb640deb4f0ea1f9;p=ccan diff --git a/ccan/htable/tools/hsearchspeed.c b/ccan/htable/tools/hsearchspeed.c index ea1a3f5c..88280114 100644 --- a/ccan/htable/tools/hsearchspeed.c +++ b/ccan/htable/tools/hsearchspeed.c @@ -1,9 +1,9 @@ /* Simple speed tests for a hash of strings using hsearch */ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -15,51 +15,43 @@ #include /* 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; char **w; ENTRY *words, *misswords; - w = strsplit(NULL, grab_file(NULL, - argv[1] ? argv[1] : "/usr/share/dict/words", - NULL), "\n"); - num = talloc_array_length(w) - 1; + w = tal_strsplit(NULL, grab_file(NULL, + argv[1] ? argv[1] : "/usr/share/dict/words"), "\n", STR_NO_EMPTY); + num = tal_count(w) - 1; printf("%zu words\n", num); hcreate(num+num/3); - words = talloc_array(w, ENTRY, num); + words = tal_arr(w, ENTRY, num); for (i = 0; i < num; i++) { words[i].key = w[i]; words[i].data = words[i].key; } /* Append and prepend last char for miss testing. */ - misswords = talloc_array(w, ENTRY, num); + misswords = tal_arr(w, ENTRY, num); for (i = 0; i < num; i++) { char lastc; if (strlen(w[i])) lastc = w[i][strlen(w[i])-1]; else lastc = 'z'; - misswords[i].key = talloc_asprintf(misswords, "%c%s%c%c", - lastc, w[i], - lastc, lastc); + misswords[i].key = tal_fmt(misswords, "%c%s%c%c", + lastc, w[i], lastc, lastc); } printf("#01: Initial insert: ");