Hi,

Use a monotonic clock for the elapsed time trial.

--
Scott Cheloha

Index: bin/md5/md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.91
diff -u -p -r1.91 md5.c
--- bin/md5/md5.c       22 May 2017 16:00:47 -0000      1.91
+++ bin/md5/md5.c       10 Sep 2017 19:29:05 -0000
@@ -750,7 +750,7 @@ void
 digest_time(struct hash_list *hl, int times)
 {
        struct hash_function *hf;
-       struct timeval start, stop, res;
+       struct timespec start, stop, res;
        union ANY_CTX context;
        u_int i;
        u_char data[TEST_BLOCK_LEN];
@@ -769,14 +769,14 @@ 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);
+               clock_gettime(CLOCK_MONOTONIC, &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);
-               elapsed = res.tv_sec + res.tv_usec / 1000000.0;
+               clock_gettime(CLOCK_MONOTONIC, &stop);
+               timespecsub(&stop, &start, &res);
+               elapsed = res.tv_sec + res.tv_nsec / 1000000000.0;
 
                (void)printf("\nDigest = %s\n", digest);
                (void)printf("Time   = %f seconds\n", elapsed);

Reply via email to