Skip to content

Commit 7c3d0ed

Browse files
authored
bench: refactor to use dynamic memory allocation in blas/ext/base/dapx
PR-URL: stdlib-js#8646 Ref: stdlib-js#8643 Reviewed-by: Athan Reines <[email protected]>
1 parent 3c1ebd1 commit 7c3d0ed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/c/benchmark.length.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ static double rand_double( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
double x[ len ];
99+
double *x;
100100
double t;
101101
int i;
102102

103+
x = (double *)malloc( len * sizeof(double) );
103104
for ( i = 0; i < len; i++ ) {
104105
x[ i ] = ( rand_double()*200.0 ) - 100.0;
105106
}
@@ -116,15 +117,17 @@ static double benchmark1( int iterations, int len ) {
116117
if ( x[ 0 ] != x[ 0 ] ) {
117118
printf( "should not return NaN\n" );
118119
}
120+
free( x );
119121
return elapsed;
120122
}
121123

122124
static double benchmark2( int iterations, int len ) {
123125
double elapsed;
124-
double x[ len ];
126+
double *x;
125127
double t;
126128
int i;
127129

130+
x = (double *)malloc( len * sizeof(double) );
128131
for ( i = 0; i < len; i++ ) {
129132
x[ i ] = ( rand_double()*200.0 ) - 100.0;
130133
}
@@ -141,6 +144,7 @@ static double benchmark2( int iterations, int len ) {
141144
if ( x[ 0 ] != x[ 0 ] ) {
142145
printf( "should not return NaN\n" );
143146
}
147+
free( x );
144148
return elapsed;
145149
}
146150

0 commit comments

Comments
 (0)