summaryrefslogtreecommitdiff
path: root/mbw.c
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2023-05-02 16:38:33 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2023-05-02 16:38:33 +0200
commit9bb207427359e0a4004f6300d39ee523c3bd6637 (patch)
tree43bd57324831c55f4830e4b4098d1c5c3b2d5187 /mbw.c
parent1d53dc100ce18877101bc0e06e37941df7fc67ae (diff)
use monotonic clock for benchmarks. gettimeofday is a really bad idea
Diffstat (limited to 'mbw.c')
-rw-r--r--mbw.c20
1 files 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<arr_size; t++) {
arr_b[t]=arr_a[t];
}
- gettimeofday(&endtime, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &endtime);
}
#endif
- te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
+ te=((double)(endtime.tv_sec*1000000000-starttime.tv_sec*1000000000+endtime.tv_nsec-starttime.tv_nsec))/1000000000;
return te;
}