From b87a5ee1f317d715049aa5989d8620343b3c2476 Mon Sep 17 00:00:00 2001 From: Yashar Alan Zenker Date: Sun, 5 Jul 2026 00:25:29 +0200 Subject: [PATCH] Removed: Wierd benchmarking switch statement --- Implementierung/main.c | 56 ++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/Implementierung/main.c b/Implementierung/main.c index af4891e..734c097 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -28,60 +28,40 @@ unsigned tests(void) { void benchmarking(size_t benchmarking_amount, int version_to_use, float complex complexA, size_t width, ssize_t height, float resolution, unsigned n, _Bool colored, unsigned char *tempArr) { struct timespec start; struct timespec end; - switch (version_to_use) + void (*tricorn_implementation)(float complex, size_t, ssize_t, float, unsigned, _Bool, unsigned char*); + + switch (version_to_use) { - case 0: // Uses highly optimized SIMD and threaded version / main implementation - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + case 0: // Uses highly optimized SIMD and threaded version / main implementatio + tricorn_implementation = tricorn; break; case 1: // Uses unoptimised comparison implementation - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn_V1(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + tricorn_implementation = tricorn_V1; break; case 2: // Uses optimized SISD version - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn_V2(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + tricorn_implementation = tricorn_V2; break; case 3: // Uses unoptimized SIMD version - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn_V3(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + tricorn_implementation = tricorn_V3; break; case 4: // Uses highly optimized SIMD - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn_V4(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + tricorn_implementation = tricorn_V4; break; case 5: // Experimental cleanups and inlines / for testing - clock_gettime(CLOCK_MONOTONIC, &start); - for (size_t i = 0; i < benchmarking_amount; i++) - { - tricorn_V5(complexA,width,height,resolution,n,colored,tempArr); - } - clock_gettime(CLOCK_MONOTONIC, &end); + tricorn_implementation = tricorn_V5; break; default: printf("Invalid version to use"); return; } + + clock_gettime(CLOCK_MONOTONIC, &start); + for (size_t i = 0; i < benchmarking_amount; i++) + { + tricorn_implementation(complexA,width,height,resolution,n,colored,tempArr); + } + clock_gettime(CLOCK_MONOTONIC, &end); + double time = end.tv_sec- start.tv_sec + 1e-9 * (end.tv_nsec- start.tv_nsec); printf("The total amount of time spent for %zu function calls: %lf\n", benchmarking_amount,time); double average = time / benchmarking_amount;