Skip to content

Commit 1783683

Browse files
committed
fixing C lint error
1 parent 14a166d commit 1783683

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

lib/node_modules/@stdlib/math/strided/special/dabs2/benchmark/c/benchmark.length.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,49 @@ static double rand_double( void ) {
9494
* @param len array length
9595
* @return elapsed time in seconds
9696
*/
97-
static double benchmark( int iterations, int len ) {
97+
static double benchmark(int iterations, int len) {
9898
double elapsed;
99-
double x[ len ];
100-
double y[ len ];
99+
double *x;
100+
double *y;
101101
double t;
102102
int i;
103103

104-
for ( i = 0; i < len; i++ ) {
105-
x[ i ] = ( rand_double()*200.0 ) - 100.0;
106-
y[ i ] = 0.0;
104+
// Allocate input array:
105+
x = (double*) malloc(len * sizeof(double));
106+
if (x == NULL) {
107+
printf("Error allocating memory.\n");
108+
exit(1);
109+
}
110+
111+
// Allocate output array:
112+
y = (double*) malloc(len * sizeof(double));
113+
if (y == NULL) {
114+
free(x);
115+
printf("Error allocating memory.\n");
116+
exit(1);
117+
}
118+
119+
for (i = 0; i < len; i++) {
120+
x[i] = (rand_double()*200.0) - 100.0;
121+
y[i] = 0.0;
107122
}
108123
t = tic();
109-
for ( i = 0; i < iterations; i++ ) {
110-
stdlib_strided_dabs2( len, x, 1, y, 1 );
111-
if ( y[ 0 ] != y[ 0 ] ) {
112-
printf( "should not return NaN\n" );
124+
for (i = 0; i < iterations; i++) {
125+
stdlib_strided_dabs2(len, x, 1, y, 1);
126+
if (y[0] != y[0]) {
127+
printf("should not return NaN\n");
113128
break;
114129
}
115130
}
116131
elapsed = tic() - t;
117-
if ( y[ 0 ] != y[ 0 ] ) {
118-
printf( "should not return NaN\n" );
132+
if (y[0] != y[0]) {
133+
printf("should not return NaN\n");
119134
}
135+
136+
// Free allocated memory:
137+
free(x);
138+
free(y);
139+
120140
return elapsed;
121141
}
122142

0 commit comments

Comments
 (0)