On Mon, 11 Sep 2017 16:19:02 +0200, Christian Weisgerber wrote:

> FreeBSD uses getrusage() to fetch the user time used.  I think that 
> makes more sense.
> 
> https://svnweb.freebsd.org/base/head/sbin/md5/md5.c?revision=307658&view=mark
> up#l293

Indeed.  There's no point in including system time in the measurement.

 - todd

Index: bin/md5/md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.91
diff -u -p -u -r1.91 md5.c
--- bin/md5/md5.c       22 May 2017 16:00:47 -0000      1.91
+++ bin/md5/md5.c       11 Sep 2017 15:48:29 -0000
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/queue.h>
+#include <sys/resource.h>
 #include <netinet/in.h>
 #include <ctype.h>
 #include <err.h>
@@ -750,7 +751,8 @@ void
 digest_time(struct hash_list *hl, int times)
 {
        struct hash_function *hf;
-       struct timeval start, stop, res;
+       struct rusage start, stop;
+       struct timeval res;
        union ANY_CTX context;
        u_int i;
        u_char data[TEST_BLOCK_LEN];
@@ -769,13 +771,13 @@ digest_time(struct hash_list *hl, int ti
                for (i = 0; i < TEST_BLOCK_LEN; i++)
                        data[i] = (u_char)(i & 0xff);
 
-               gettimeofday(&start, NULL);
+               getrusage(RUSAGE_SELF, &start);
                hf->init(&context);
                for (i = 0; i < count; i++)
                        hf->update(&context, data, (size_t)TEST_BLOCK_LEN);
                digest_end(hf, &context, digest, sizeof(digest), hf->base64);
-               gettimeofday(&stop, NULL);
-               timersub(&stop, &start, &res);
+               getrusage(RUSAGE_SELF, &stop);
+               timersub(&stop.ru_utime, &start.ru_utime, &res);
                elapsed = res.tv_sec + res.tv_usec / 1000000.0;
 
                (void)printf("\nDigest = %s\n", digest);

Reply via email to