fixed: switch statement out of the benchmarking + parsing no longer accepts invalid floating numbers
This commit is contained in:
+92
-35
@@ -27,41 +27,61 @@ 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) {
|
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 start;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
struct timespec end;
|
||||||
for (size_t i = 0; i < benchmarking_amount; i++)
|
|
||||||
{
|
|
||||||
switch (version_to_use)
|
switch (version_to_use)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0: // Uses highly optimized SIMD and threaded version / main implementation
|
||||||
// Uses highly optimized SIMD and threaded version / main implementation
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1: // Uses unoptimised comparison implementation
|
||||||
// Uses unoptimised comparison implementation
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn_V1(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn_V1(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2: // Uses optimized SISD version
|
||||||
// Uses optimized SISD version
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn_V2(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn_V2(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3: // Uses unoptimized SIMD version
|
||||||
// Uses unoptimized SIMD version
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn_V3(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn_V3(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4: // Uses highly optimized SIMD
|
||||||
// Uses highly optimized SIMD
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn_V4(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn_V4(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5: // Experimental cleanups and inlines / for testing
|
||||||
// Experimental cleanups and inlines / for testing
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
tricorn_V5(complexA,width,height,resolution,n,colored,tempArr);
|
for (size_t i = 0; i < benchmarking_amount; i++)
|
||||||
|
{
|
||||||
|
tricorn_V5(complexA,width,height,resolution,n,colored,tempArr);
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
printf("Invalid version to use");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
struct timespec end;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
||||||
double time = end.tv_sec- start.tv_sec + 1e-9 * (end.tv_nsec- start.tv_nsec);
|
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);
|
printf("The total amount of time spent for %zu function calls: %lf\n", benchmarking_amount,time);
|
||||||
double average = time / benchmarking_amount;
|
double average = time / benchmarking_amount;
|
||||||
@@ -138,6 +158,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
int version_to_use = 0; // actual initial value
|
int version_to_use = 0; // actual initial value
|
||||||
_Bool colored = 0; // actual initial value
|
_Bool colored = 0; // actual initial value
|
||||||
|
_Bool will_benchmark = false; // actual initial value
|
||||||
|
|
||||||
int amount_function_called = 0; // initial values, so that the compiler doesn't complain
|
int amount_function_called = 0; // initial values, so that the compiler doesn't complain
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
@@ -147,7 +168,6 @@ int main(int argc, char** argv)
|
|||||||
ssize_t height = 0;
|
ssize_t height = 0;
|
||||||
float resolution = 0;
|
float resolution = 0;
|
||||||
char* output_data = 0;
|
char* output_data = 0;
|
||||||
_Bool will_benchmark = false;
|
|
||||||
|
|
||||||
|
|
||||||
opt_long = getopt_long(argc,argv,optstring, long_options, NULL);
|
opt_long = getopt_long(argc,argv,optstring, long_options, NULL);
|
||||||
@@ -168,7 +188,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
case 'B': // done, function needed
|
case 'B': // done, function needed
|
||||||
// wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later)
|
// wird die Laufzeit der angegebenen Implementierung gemessen und ausgegeben (do this later)
|
||||||
int amount_function_called = strtol(optarg,NULL,10);
|
amount_function_called = strtol(optarg,NULL,10);
|
||||||
if (amount_function_called <= 0) {
|
if (amount_function_called <= 0) {
|
||||||
printf("Invalid benchmarking input, the value should be greater than 0\n");
|
printf("Invalid benchmarking input, the value should be greater than 0\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -180,23 +200,53 @@ int main(int argc, char** argv)
|
|||||||
// Das Argument dieser Option gibt die Anzahl an Wiederholungen des Funktionsaufrufs an, z. B.-B 5 .
|
// Das Argument dieser Option gibt die Anzahl an Wiederholungen des Funktionsaufrufs an, z. B.-B 5 .
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's': {
|
||||||
char* imaginary_string;
|
char *imaginary_string;
|
||||||
|
char *end;
|
||||||
|
|
||||||
starting_point_real = strtof(optarg,&imaginary_string); // split into two
|
starting_point_real = strtof(optarg,&imaginary_string); // split into two
|
||||||
starting_point_imaginary = strtof(imaginary_string + 1,NULL); // this is horrible
|
if (imaginary_string == optarg || *imaginary_string != ',')
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid first number or missing comma: %s\n",optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
starting_point_imaginary = strtof(imaginary_string + 1, &end); // second part, the imaginary part
|
||||||
|
if (end == imaginary_string + 1 || *end != '\0')
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid second number or extra characters: %s\n",optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
printf("real %f, img %f\n", starting_point_real,starting_point_imaginary);
|
printf("real %f, img %f\n", starting_point_real,starting_point_imaginary);
|
||||||
|
|
||||||
|
|
||||||
// s <Realteil>,<Imaginärteil> — Startpunkt der Berechnung
|
// s <Realteil>,<Imaginärteil> — Startpunkt der Berechnung
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'd':
|
case 'd': {
|
||||||
char* height_string;
|
char* height_string;
|
||||||
|
char *end;
|
||||||
width = strtol(optarg,&height_string,10);
|
width = strtol(optarg,&height_string,10);
|
||||||
height = strtol(height_string + 1,NULL,10);
|
|
||||||
|
if (height_string == optarg || *height_string != ',')
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid width or missing comma: %s\n",optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
height = strtol(height_string + 1,&end,10);
|
||||||
|
|
||||||
|
if (end == height_string + 1 || *end != '\0')
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid height or extra characters: %s\n",optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
printf("width %zu, height %zd\n", width,height);
|
printf("width %zu, height %zd\n", width,height);
|
||||||
// -d <Zahl>,<Zahl> —Breite und Höhe des Bildausschnitts
|
// -d <Zahl>,<Zahl> —Breite und Höhe des Bildausschnitts
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
n = strtol(optarg,NULL,10);
|
n = strtol(optarg,NULL,10);
|
||||||
@@ -204,11 +254,18 @@ int main(int argc, char** argv)
|
|||||||
// -n <Zahl> —MaximaleAnzahlanIterationen pro Bildpixel
|
// -n <Zahl> —MaximaleAnzahlanIterationen pro Bildpixel
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r': {
|
||||||
resolution = strtof(optarg,NULL);
|
char *end;
|
||||||
|
resolution = strtof(optarg,&end);
|
||||||
|
if (end == optarg || *end != '\0')
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid floating point number: %s\n",optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
printf("r:%f\n", resolution);
|
printf("r:%f\n", resolution);
|
||||||
// r <Floating Point Zahl> —Schrittweite pro Bildpixel
|
// r <Floating Point Zahl> —Schrittweite pro Bildpixel
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
output_data = malloc(strlen(optarg) + 1);
|
output_data = malloc(strlen(optarg) + 1);
|
||||||
@@ -218,7 +275,7 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C': // done
|
case 'C': // done
|
||||||
colored = 1;
|
colored = true;
|
||||||
printf("colored:%d\n",colored);
|
printf("colored:%d\n",colored);
|
||||||
// C|--color —Farbausgabe
|
// C|--color —Farbausgabe
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user