Skip to content
Closed
Changes from all commits
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 @@ -94,29 +94,49 @@ static double rand_double( void ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
static double benchmark(int iterations, int len) {
double elapsed;
double x[ len ];
double y[ len ];
double *x;
double *y;
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*200.0 ) - 100.0;
y[ i ] = 0.0;
// Allocate input array:
x = (double*) malloc(len * sizeof(double));
if (x == NULL) {
printf("Error allocating memory.\n");
exit(1);
}

// Allocate output array:
y = (double*) malloc(len * sizeof(double));
if (y == NULL) {
free(x);
printf("Error allocating memory.\n");
exit(1);
}

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_dabs2( len, x, 1, y, 1 );
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
for (i = 0; i < iterations; i++) {
stdlib_strided_dabs2(len, x, 1, y, 1);
if (y[0] != y[0]) {
printf("should not return NaN\n");
break;
}
}
elapsed = tic() - t;
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
if (y[0] != y[0]) {
printf("should not return NaN\n");
}

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

return elapsed;
}

Expand Down
Loading