Skip to content

Commit f23afb4

Browse files
farazghanikgryte
andauthored
bench: refactor to use dynamic memory allocation in blas/ext/base/dnanasum
PR-URL: #8714 Ref: #8643 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 30ab067 commit f23afb4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ 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 v;
101101
double t;
102102
int i;
103103

104+
x = (double *) malloc( len * sizeof( double ) );
104105
for ( i = 0; i < len; i++ ) {
105106
if ( rand_double() < 0.2 ) {
106107
x[ i ] = 0.0 / 0.0; // NaN
@@ -121,6 +122,7 @@ static double benchmark1( int iterations, int len ) {
121122
if ( v != v ) {
122123
printf( "should not return NaN\n" );
123124
}
125+
free( x );
124126
return elapsed;
125127
}
126128

@@ -133,11 +135,12 @@ static double benchmark1( int iterations, int len ) {
133135
*/
134136
static double benchmark2( int iterations, int len ) {
135137
double elapsed;
136-
double x[ len ];
138+
double *x;
137139
double v;
138140
double t;
139141
int i;
140142

143+
x = (double *) malloc( len * sizeof( double ) );
141144
for ( i = 0; i < len; i++ ) {
142145
if ( rand_double() < 0.2 ) {
143146
x[ i ] = 0.0 / 0.0; // NaN
@@ -158,6 +161,7 @@ static double benchmark2( int iterations, int len ) {
158161
if ( v != v ) {
159162
printf( "should not return NaN\n" );
160163
}
164+
free( x );
161165
return elapsed;
162166
}
163167

0 commit comments

Comments
 (0)