From 9bb207427359e0a4004f6300d39ee523c3bd6637 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 2 May 2023 16:38:33 +0200 Subject: use monotonic clock for benchmarks. gettimeofday is a really bad idea --- mbw.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mbw.c b/mbw.c index 7c18883..93ec55c 100644 --- a/mbw.c +++ b/mbw.c @@ -185,15 +185,15 @@ void sync_threads() */ double worker() { - struct timeval starttime, endtime; + struct timespec starttime, endtime; double te; /* array size in bytes */ #ifdef MULTITHREADED - gettimeofday(&starttime, NULL); + clock_gettime(CLOCK_MONOTONIC, &starttime); start_threads(); await_threads(); - gettimeofday(&endtime, NULL); + clock_gettime(CLOCK_MONOTONIC, &endtime); sync_threads(); #else @@ -201,30 +201,30 @@ double worker() unsigned long long array_bytes=arr_size*long_size; unsigned long long t; if(test_type==TEST_MEMCPY) { /* memcpy test */ - gettimeofday(&starttime, NULL); + clock_gettime(CLOCK_MONOTONIC, &starttime); memcpy(arr_b, arr_a, array_bytes); - gettimeofday(&endtime, NULL); + clock_gettime(CLOCK_MONOTONIC, &endtime); } else if(test_type==TEST_MCBLOCK) { /* memcpy block test */ char* src = (char*)arr_a; char* dst = (char*)arr_b; - gettimeofday(&starttime, NULL); + clock_gettime(CLOCK_MONOTONIC, &starttime); for (t=array_bytes; t >= block_size; t-=block_size, src+=block_size){ dst=(char *) memcpy(dst, src, block_size) + block_size; } if(t) { dst=(char *) memcpy(dst, src, t) + t; } - gettimeofday(&endtime, NULL); + clock_gettime(CLOCK_MONOTONIC, &endtime); } else if(test_type==TEST_DUMB) { /* dumb test */ - gettimeofday(&starttime, NULL); + clock_gettime(CLOCK_MONOTONIC, &starttime); for(t=0; t