diff options
author | Oliver Upton <oliver.upton@linux.dev> | 2023-11-28 21:29:22 +0000 |
---|---|---|
committer | Oliver Upton <oliver.upton@linux.dev> | 2023-11-28 21:29:22 +0000 |
commit | 9240756b27c418571bc53cdc493e919bf8d48a09 (patch) | |
tree | 9dbadb968cda62d403c40bc53a9ed510c2c6a41f | |
parent | f798a804c604f52716af50c7ca48b29a8c18da35 (diff) | |
download | aarch64-memcpy-9240756b27c418571bc53cdc493e919bf8d48a09.tar.gz |
report bandwidth
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
-rw-r--r-- | main.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include <sys/mman.h> +#include <time.h> #include <unistd.h> #include "memcpy.h" @@ -86,10 +87,23 @@ static void do_memcpy(void *dst, const void *src) } } +#define NSEC_PER_SEC 1000000000UL + +static void report_bandwidth(struct timespec *start, struct timespec *end) +{ + double nsec = ((end->tv_sec - start->tv_sec) * NSEC_PER_SEC) + + (end->tv_nsec - start->tv_nsec); + double data = test_size * test_iterations; + double rate = (data / (nsec / NSEC_PER_SEC)) / GB; + + printf("Rate: %.03f GiB/sec\n", rate); +} + static void run_test(void) { void *dst = setup_test_buffer(); void *src = setup_test_buffer(); + struct timespec start, end; size_t i; printf("Iters: %lu\n", test_iterations); @@ -97,9 +111,15 @@ static void run_test(void) printf("Source: [%p, %p)\n", src, src + test_size); printf("Dest: [%p, %p)\n", dst, dst + test_size); + assert(!clock_gettime(CLOCK_MONOTONIC, &start)); + for (i = 0; i < test_iterations; i++) do_memcpy(dst, src); + assert(!clock_gettime(CLOCK_MONOTONIC, &end)); + + report_bandwidth(&start, &end); + destroy_test_buffer(dst); destroy_test_buffer(src); } |