From a0fbacdb5405ab6890bc32da6284ebe5b2699a8a Mon Sep 17 00:00:00 2001 From: wangjianfeng Date: Sun, 7 Apr 2024 17:26:44 +0800 Subject: [PATCH] [Revise] add latency and bandwidth in benchmark --- FastMemcpy.c | 25 ++++++++++++++++++++----- FastMemcpy_Avx.c | 24 +++++++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/FastMemcpy.c b/FastMemcpy.c index 5021bcc..3e0808f 100644 --- a/FastMemcpy.c +++ b/FastMemcpy.c @@ -77,9 +77,16 @@ void benchmark(int dstalign, int srcalign, size_t size, int times) free(DATA1); free(DATA2); - printf("result(dst %s, src %s): memcpy_fast=%dms memcpy=%d ms\n", - dstalign? "aligned" : "unalign", - srcalign? "aligned" : "unalign", (int)t2, (int)t1); + float lat1 = (float)t1 * 1000000 / times; + float lat2 = (float)t2 * 1000000 / times; + + float bw1 = (float)size * times / 1024 / 1024 / 1024 / t1 * 1000; + float bw2 = (float)size * times / 1024 / 1024 / 1024 / t2 * 1000; + + printf("result(dst %s, src %s): \tlatency(memcpy_fast:%.1fns memcpy=%.1fns) \tbandwith(memcpy_fast:%.1fGB/s memcpy=%.1fGB/s)\n", + dstalign? "aligned" : "unalign", + srcalign? "aligned" : "unalign", + lat2, lat1, bw2, bw1); } @@ -126,8 +133,16 @@ void random_bench(int maxsize, int times) memcpy_fast(A + offset1, B + offset2, size); } t2 = gettime() - t2; - printf("benchmark random access:\n"); - printf("memcpy_fast=%dms memcpy=%dms\n\n", (int)t2, (int)t1); + + float lat1 = (float)t1 * 1000000 / times; + float lat2 = (float)t2 * 1000000 / times; + + float bw1 = (float)maxsize / 2 * times / 1024 / 1024 / 1024 / t1 * 1000; + float bw2 = (float)maxsize / 2 * times / 1024 / 1024 / 1024 / t2 * 1000; + + printf("benchmark random access(size=1~%d bytes, times=%d):\n", maxsize, times); + printf("result: \tlatency(memcpy_fast:%.1fns memcpy=%.1fns) \tbandwith(memcpy_fast:%.1fGB/s memcpy=%.1fGB/s)\n", + lat2, lat1, bw2, bw1); } diff --git a/FastMemcpy_Avx.c b/FastMemcpy_Avx.c index 6538c6b..a37ee13 100644 --- a/FastMemcpy_Avx.c +++ b/FastMemcpy_Avx.c @@ -79,10 +79,16 @@ void benchmark(int dstalign, int srcalign, size_t size, int times) free(DATA1); free(DATA2); + float lat1 = (float)t1 * 1000000 / times; + float lat2 = (float)t2 * 1000000 / times; - printf("result(dst %s, src %s): memcpy_fast=%dms memcpy=%d ms\n", - dstalign? "aligned" : "unalign", - srcalign? "aligned" : "unalign", (int)t2, (int)t1); + float bw1 = (float)size * times / 1024 / 1024 / 1024 / t1 * 1000; + float bw2 = (float)size * times / 1024 / 1024 / 1024 / t2 * 1000; + + printf("result(dst %s, src %s): \tlatency(memcpy_fast:%.1fns memcpy=%.1fns) \tbandwith(memcpy_fast:%.1fGB/s memcpy=%.1fGB/s)\n", + dstalign? "aligned" : "unalign", + srcalign? "aligned" : "unalign", + lat2, lat1, bw2, bw1); } @@ -129,8 +135,16 @@ void random_bench(int maxsize, int times) memcpy_fast(A + offset1, B + offset2, size); } t2 = gettime() - t2; - printf("benchmark random access:\n"); - printf("memcpy_fast=%dms memcpy=%dms\n\n", (int)t2, (int)t1); + + float lat1 = (float)t1 * 1000000 / times; + float lat2 = (float)t2 * 1000000 / times; + + float bw1 = (float)maxsize / 2 * times / 1024 / 1024 / 1024 / t1 * 1000; + float bw2 = (float)maxsize / 2 * times / 1024 / 1024 / 1024 / t2 * 1000; + + printf("benchmark random access(size=1~%d bytes, times=%d):\n", maxsize, times); + printf("result: \tlatency(memcpy_fast:%.1fns memcpy=%.1fns) \tbandwith(memcpy_fast:%.1fGB/s memcpy=%.1fGB/s)\n", + lat2, lat1, bw2, bw1); }