Cleaned up test(), moved temporaryArray into benchmarking function
This commit is contained in:
+57
-53
@@ -16,16 +16,24 @@
|
|||||||
#include "tricorn_V3.h"
|
#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 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 start;
|
||||||
struct timespec end;
|
struct timespec end;
|
||||||
void (*tricorn_implementation)(float complex, size_t, ssize_t, float, unsigned, _Bool, unsigned char*);
|
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)
|
switch (version_to_use)
|
||||||
{
|
{
|
||||||
case 0: // Uses highly optimized SIMD and threaded version / main implementation
|
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);
|
printf("The total amount of time spent for %zu function calls: %lf seconds\n", benchmarking_amount,time);
|
||||||
double average = time / benchmarking_amount;
|
double average = time / benchmarking_amount;
|
||||||
printf("Average time per function: %lf seconds\n", average);
|
printf("Average time per function: %lf seconds\n", average);
|
||||||
|
|
||||||
|
free(tempArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned tests(void) {
|
unsigned tests(void) {
|
||||||
|
|
||||||
printf("Doing testing\n\n");
|
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\nTest 1: Default image, coloured\n");
|
||||||
printf("\n\n");
|
float complex start = -2.0f - 0.5f*I;
|
||||||
benchmarking(TESTING_AMOUNT,0,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
|
size_t width = 1920;
|
||||||
printf("\n\n");
|
size_t height = 1080;
|
||||||
benchmarking(TESTING_AMOUNT,1,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
|
float resolution = 0.001f;
|
||||||
printf("\n\n");
|
int n = 200;
|
||||||
benchmarking(TESTING_AMOUNT,2,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
|
_Bool colored = true;
|
||||||
printf("\n\n");
|
|
||||||
benchmarking(10,3,-2.0f - 0.5f*I, width, height, 0.001f, 200, true, tempArrColored);
|
|
||||||
|
|
||||||
|
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\nTest 2: Ultra high resolution low iterations\n");
|
||||||
printf("\n\n");
|
start = -2.0f - 0.5f*I;
|
||||||
benchmarking(TESTING_AMOUNT,0,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
|
width = 7680;
|
||||||
printf("\n\n");
|
height = 4320;
|
||||||
benchmarking(TESTING_AMOUNT,1,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
|
resolution = 0.001f;
|
||||||
printf("\n\n");
|
n = 5;
|
||||||
benchmarking(TESTING_AMOUNT,2,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
|
|
||||||
printf("\n\n");
|
for(int i = 0; i < NUMBER_OF_VERSIONS; i++) {
|
||||||
benchmarking(TESTING_AMOUNT,3,-2.0f - 0.5f*I, ultra_width, ultra_height, 0.001f, 5, true, tempArrUltraColored);
|
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\nTest 3: Zoomed on fractal edge\n");
|
||||||
printf("\n\n");
|
start = -1.431f - 0.250f*I;
|
||||||
benchmarking(TESTING_AMOUNT,0,-1.431f - 0.250f*I, 1024, 1024, 0.0005f, 3000, false, tempArrNotColored);
|
width = 1024;
|
||||||
printf("\n\n");
|
height = 1024;
|
||||||
benchmarking(TESTING_AMOUNT,1,-1.1f - 0.0f*I, 1024, 1024, 0.0005f, 3000, false, tempArrNotColored);
|
resolution = 0.0005f;
|
||||||
printf("\n\n");
|
n = 3000;
|
||||||
benchmarking(TESTING_AMOUNT,2,-1.1f - 0.0f*I, 1024, 512, 0.0005f, 3000, false, tempArrNotColored);
|
|
||||||
printf("\n\n");
|
for(int i = 0; i < NUMBER_OF_VERSIONS; i++) {
|
||||||
benchmarking(TESTING_AMOUNT,3,-1.1f - 0.0f*I, 1024, 512, 0.0005f, 3000, false, tempArrNotColored);
|
printf("\n\n");
|
||||||
|
benchmarking(TESTING_AMOUNT,i,start, width, height, resolution, n, colored);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\nTest 4: Pure Black\n");
|
printf("\nTest 4: Pure Black\n");
|
||||||
printf("\n\n");
|
start = 0;
|
||||||
benchmarking(TESTING_AMOUNT,0,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
|
width = 1920;
|
||||||
printf("\n\n");
|
height = 1080;
|
||||||
benchmarking(TESTING_AMOUNT,1,0, width, height, 0.00001f, 1000, false, tempArrNotColored);
|
resolution = 0.00001f;
|
||||||
printf("\n\n");
|
n = 1000;
|
||||||
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);
|
|
||||||
|
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +458,7 @@ int main(int argc, char** argv)
|
|||||||
if (will_benchmark)
|
if (will_benchmark)
|
||||||
{
|
{
|
||||||
printf("\nDoing benchmarking. No images will be created\n");
|
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(tempArr);
|
||||||
free(output_data);
|
free(output_data);
|
||||||
return EXIT_SUCCESS;
|
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 row_width = width * bytesPerColor + row_padding; // Calculate row width with padding
|
||||||
|
|
||||||
size_t image_size = actual_height * row_width;
|
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 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
|
// File header - contains information about the file
|
||||||
|
|||||||
Reference in New Issue
Block a user