diff --git a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c index 58c6e2c22fc2..b9b331caf084 100644 --- a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c @@ -104,32 +104,54 @@ 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; +static double benchmark(int iterations, int len) { + double elapsed; + 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; - } - 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; -} + // 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); + } + // 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; +} /** * Main execution sequence. */