diff options
author | silby <silby@FreeBSD.org> | 2003-02-14 04:48:06 +0000 |
---|---|---|
committer | silby <silby@FreeBSD.org> | 2003-02-14 04:48:06 +0000 |
commit | 6d6e9671a534acb2aedf8ddc808b5305d35e1085 (patch) | |
tree | d6ec51c95af83c2f3b7221e4622ec9a5d64dafed /sbin/md5 | |
parent | ee568cc79e5011ade30e0ab18dc592ee3152cbca (diff) | |
download | FreeBSD-src-6d6e9671a534acb2aedf8ddc808b5305d35e1085.zip FreeBSD-src-6d6e9671a534acb2aedf8ddc808b5305d35e1085.tar.gz |
Improvements to md5.c so that it uses getrusage to time
benchmarks, and prints out results in float format.
Diffstat (limited to 'sbin/md5')
-rw-r--r-- | sbin/md5/md5.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c index 930f7cc..5c3bbb7 100644 --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -23,6 +23,8 @@ static const char rcsid[] = #endif /* not lint */ #include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> #include <err.h> #include <md5.h> #include <stdio.h> @@ -131,7 +133,9 @@ static void MDTimeTrial(void) { MD5_CTX context; - time_t endTime, startTime; + struct rusage before, after; + struct timeval total; + float seconds; unsigned char block[TEST_BLOCK_LEN]; unsigned int i; char *p, buf[33]; @@ -146,7 +150,7 @@ MDTimeTrial(void) block[i] = (unsigned char) (i & 0xff); /* Start timer */ - time(&startTime); + getrusage(0, &before); /* Digest blocks */ MD5Init(&context); @@ -155,16 +159,16 @@ MDTimeTrial(void) p = MD5End(&context,buf); /* Stop timer */ - time(&endTime); + getrusage(0, &after); + timersub(&after.ru_utime, &before.ru_utime, &total); + seconds = total.tv_sec + (float) total.tv_usec / 1000000; printf(" done\n"); printf("Digest = %s", p); - printf("\nTime = %ld seconds\n", (long) (endTime - startTime)); - /* Be careful that endTime-startTime is not zero. (Bug fix from Ric - * Anderson, ric@Artisoft.COM.) */ + printf("\nTime = %f seconds\n", seconds); printf - ("Speed = %ld bytes/second\n", - (long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / ((endTime - startTime) != 0 ? (long)(endTime - startTime) : 1)); + ("Speed = %f bytes/second\n", + (float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds); } /* * Digests a reference suite of strings and prints the results. |