Cleaned up test(), moved temporaryArray into benchmarking function

This commit is contained in:
Nikola
2026-07-15 19:58:39 +02:00
parent 1833051ff1
commit e610ca23bf
+57 -53
View File
@@ -16,16 +16,24 @@
#include "tricorn_V3.h"
const uint16_t TESTING_AMOUNT = 100;
const uint16_t TESTING_AMOUNT = 10;
const uint16_t NUMBER_OF_VERSIONS = 4;
void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height,_Bool color);
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) {
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) {
struct timespec start;
struct timespec end;
void (*tricorn_implementation)(float complex, size_t, ssize_t, float, unsigned, _Bool, unsigned char*);
unsigned int bytePerColor = colored ? 3 : 1;
unsigned char *tempArr = malloc(width*height*bytePerColor);
if(tempArr == NULL) {
fprintf(stderr,"Could not allocate memory for buffer");
exit(EXIT_FAILURE);
}
switch (version_to_use)
{
case 0: // Uses highly optimized SIMD and threaded version / main implementation
@@ -62,71 +70,66 @@ void benchmarking(size_t benchmarking_amount, int version_to_use, float complex
printf("The total amount of time spent for %zu function calls: %lf seconds\n", benchmarking_amount,time);
double average = time / benchmarking_amount;
printf("Average time per function: %lf seconds\n", average);
free(tempArr);
}
unsigned tests(void) {
printf("Doing testing\n\n");
size_t width = 1920;
size_t ultra_width = 7680;
size_t height = 1080;
size_t ultra_height = 4320;
unsigned char *tempArrColored = malloc(width*height*3);
unsigned char *tempArrNotColored = malloc(width*height*1);
unsigned char *tempArrUltraColored = malloc(ultra_width*ultra_height*3);
if (tempArrColored == NULL || tempArrNotColored == NULL)
{
fprintf(stderr,"Failed to allocate space for image\n");
return EXIT_FAILURE;
}
printf("\n\n\nTest 1: Default image, coloured\n");
printf("\n\n");
benchmarking(TESTING_AMOUNT,0,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,1,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,2,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
printf("\n\n");
benchmarking(10,3,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
float complex start = -2.0f - 0.5f*I;
size_t width = 1920;
size_t height = 1080;
float resolution = 0.001f;
int n = 200;
_Bool colored = true;
for(int i = 0; i < NUMBER_OF_VERSIONS;i++) {
printf("\n\n");
benchmarking(TESTING_AMOUNT,i,start, width, height, resolution, n, colored);
}
printf("\n\n\nTest 2: Ultra high resolution low iterations\n");
printf("\n\n");
benchmarking(TESTING_AMOUNT,0,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,1,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,2,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,3,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
start = -2.0f - 0.5f*I;
width = 7680;
height = 4320;
resolution = 0.001f;
n = 5;
for(int i = 0; i < NUMBER_OF_VERSIONS; i++) {
printf("\n\n");
benchmarking(TESTING_AMOUNT,i,start, width, height, resolution, n, colored);
}
printf("\n\n\nTest 3: Zoomed on fractal edge\n");
printf("\n\n");
benchmarking(TESTING_AMOUNT,0,-1.431f - 0.250f*I, 1024, 1024, 0.0005f, 3000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,1,-1.1f - 0.0f*I, 1024, 1024, 0.0005f, 3000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,2,-1.1f - 0.0f*I, 1024, 512, 0.0005f, 3000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,3,-1.1f - 0.0f*I, 1024, 512, 0.0005f, 3000, false, tempArrNotColored);
start = -1.431f - 0.250f*I;
width = 1024;
height = 1024;
resolution = 0.0005f;
n = 3000;
for(int i = 0; i < NUMBER_OF_VERSIONS; i++) {
printf("\n\n");
benchmarking(TESTING_AMOUNT,i,start, width, height, resolution, n, colored);
}
printf("\nTest 4: Pure Black\n");
printf("\n\n");
benchmarking(TESTING_AMOUNT,0,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,1,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,2,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
printf("\n\n");
benchmarking(TESTING_AMOUNT,3,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
start = 0;
width = 1920;
height = 1080;
resolution = 0.00001f;
n = 1000;
for(int i = 0; i < NUMBER_OF_VERSIONS; i++) {
printf("\n\n");
benchmarking(TESTING_AMOUNT,i,start, width, height, resolution, n, colored);
}
free(tempArrColored);
free(tempArrNotColored);
return 0;
}
@@ -455,7 +458,7 @@ int main(int argc, char** argv)
if (will_benchmark)
{
printf("\nDoing benchmarking. No images will be created\n");
benchmarking(amount_function_called,version_to_use,complexA,width,height,resolution,n,colored,tempArr);
benchmarking(amount_function_called,version_to_use,complexA,width,height,resolution,n,colored);
free(tempArr);
free(output_data);
return EXIT_SUCCESS;
@@ -508,8 +511,9 @@ void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t he
size_t row_width = width * bytesPerColor + row_padding; // Calculate row width with padding
size_t image_size = actual_height * row_width;
size_t file_size = image_size + 54; // File size = Image Size + Headers
size_t header_offset = color ? 54 : 1078; // If colored then offset = 54 if not we add offset = 54 + 1024; 1024 Bytes for color pallete
size_t file_size = image_size + header_offset; // File size = Image Size + Headers
// File header - contains information about the file