Skip to content

Commit

Permalink
fix: apply code review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
headlessNode committed Oct 3, 2024
1 parent 29222c9 commit e4b23a9
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ static double rand_double( void ) {
*/
static double benchmark1( int iterations, int len ) {
double elapsed;
double x[ len ];
double y[ len ];
double *x;
double *y;
double t;
int i;

x = (double *)malloc( len * sizeof(double) );
y = (double *)malloc( len * sizeof(double) );

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
y[ i ] = 0.0;
Expand All @@ -118,16 +121,28 @@ static double benchmark1( int iterations, int len ) {
if ( y[ len-1 ] != y[ len-1 ] ) {
printf( "should not return NaN\n" );
}
free(x);
free(y);
return elapsed;
}

/**
* Runs a benchmark.
*
* @param iterations number of iterations
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark2( int iterations, int len ) {
double elapsed;
double x[ len ];
double y[ len ];
double *x;
double *y;
double t;
int i;

x = (double *)malloc( len * sizeof(double) );
y = (double *)malloc( len * sizeof(double) );

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
y[ i ] = 0.0;
Expand All @@ -145,6 +160,8 @@ static double benchmark2( int iterations, int len ) {
if ( y[ len-1 ] != y[ len-1 ] ) {
printf( "should not return NaN\n" );
}
free(x);
free(y);
return elapsed;
}

Expand Down

0 comments on commit e4b23a9

Please sign in to comment.