Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,47 @@ static double identity( const double x ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
double elapsed;
double x[ len ];
double y[ len ];
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*200.0 ) - 100.0;
y[ i ] = 0.0;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
stdlib_strided_dmap( len, x, 1, y, 1, identity );
if ( y[ i%len ] != y[ i%len ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( y[ i%len ] != y[ i%len ] ) {
printf( "should not return NaN\n" );
}
return elapsed;
static double benchmark(int iterations, int len) {
// Initialize all variables at declaration
double elapsed = 0.0;
double *x = malloc(len * sizeof(double)); // Use dynamic allocation instead of VLA
double *y = malloc(len * sizeof(double));
double t = 0.0;
int i = 0;

// Check if memory allocation was successful
if (x == NULL || y == NULL) {
// Handle allocation failure
free(x);
free(y);
return -1.0;
}

// Initialize arrays
for (i = 0; i < len; i++) {
x[i] = (rand_double() * 200.0) - 100.0;
y[i] = 0.0;
}

t = tic();
for (i = 0; i < iterations; i++) {
stdlib_strided_dmap(len, x, 1, y, 1, identity);
if (y[i % len] != y[i % len]) {
printf("should not return NaN\n");
break;
}
}
elapsed = tic() - t;

if (y[i % len] != y[i % len]) {
printf("should not return NaN\n");
}

// Free allocated memory
free(x);
free(y);

return elapsed;
}

/**
Expand Down
Loading