From bc79f39912aaf69fd29f81860e31378268941c34 Mon Sep 17 00:00:00 2001 From: Cem Date: Sat, 4 Jul 2026 23:09:58 +0200 Subject: [PATCH] added: benchmarking --- Implementierung/main.c | 66 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Implementierung/main.c b/Implementierung/main.c index 8579998..8fc786a 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 199309L // for CLOCK_MONOTONIC + #include #include #include @@ -5,6 +7,7 @@ #include // for getopt #include // for getopt_long #include // for strcpy +#include // for benchmarking // All implementations #include "tricorn.h" // Final implmementation @@ -22,9 +25,50 @@ unsigned tests(void) { // run the tests } -void benchmarking(void) { - // do the benchmarking +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; + clock_gettime(CLOCK_MONOTONIC, &start); + for (size_t i = 0; i < benchmarking_amount; i++) + { + switch (version_to_use) + { + case 0: + // Uses highly optimized SIMD and threaded version / main implementation + tricorn(complexA,width,height,resolution,n,colored,tempArr); + break; + case 1: + // Uses unoptimised comparison implementation + tricorn_V1(complexA,width,height,resolution,n,colored,tempArr); + break; + case 2: + // Uses optimized SISD version + tricorn_V2(complexA,width,height,resolution,n,colored,tempArr); + break; + case 3: + // Uses unoptimized SIMD version + tricorn_V3(complexA,width,height,resolution,n,colored,tempArr); + break; + case 4: + // Uses highly optimized SIMD + tricorn_V4(complexA,width,height,resolution,n,colored,tempArr); + break; + case 5: + // Experimental cleanups and inlines / for testing + tricorn_V5(complexA,width,height,resolution,n,colored,tempArr); + break; + default: + break; + } + } + struct timespec end; + 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; + printf("Average time per function:%lf", average); } + + // REMOVE LATER: interesting test command ./tricorn -s -2.0,0.6 -r 0.0010 -n 200 -d 1920,1080 -o image.bmp -C // AND FOR NEGATIVE HEIGHT: ./tricorn -s -2,-0.5 -r 0.0010 -n 200 -d 1920,-1080 -o image.bmp -C const char* help_messsage = "Help Message\n\n" @@ -103,6 +147,7 @@ int main(int argc, char** argv) ssize_t height = 0; float resolution = 0; char* output_data = 0; + _Bool will_benchmark = false; opt_long = getopt_long(argc,argv,optstring, long_options, NULL); @@ -124,12 +169,16 @@ int main(int argc, char** argv) case 'B': // done, function needed // wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later) amount_function_called = strtoul(optarg,NULL,10); - benchmarking(); + if (amount_function_called <= 0) { + printf("Invalid benchmarking input, the value should be greater than 0\n"); + return 1; + } + will_benchmark = true; printf("amount function called is %d\n", amount_function_called); // call benchmarking function // Das Argument dieser Option gibt die Anzahl an Wiederholungen des Funktionsaufrufs an, z. B.-B 5 . - return EXIT_FAILURE; + break; case 's': char* imaginary_string; @@ -206,6 +255,15 @@ int main(int argc, char** argv) if(tempArr == NULL) { exit(EXIT_FAILURE); } + + if (will_benchmark) + { + printf("\nwill do benchmarking. no images will be created\n"); + benchmarking(amount_function_called,version_to_use,complexA,width,height,resolution,n,colored,tempArr); + printf("\nbenchmarking done\n"); + return 0; + } + printf("yashar\n"); switch (version_to_use)