Skip to content

Commit 7dd0179

Browse files
authored
bench: refactor to use dynamic memory allocation in blas/base/sscal
PR-URL: stdlib-js#8819 Ref: stdlib-js#8643 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 60b2261 commit 7dd0179

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/node_modules/@stdlib/blas/base/sscal/benchmark/c/benchmark.length.c

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

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

121123
static double benchmark2( int iterations, int len ) {
122124
double elapsed;
123-
float x[ len ];
125+
float *x;
124126
double t;
125127
int i;
126128

129+
x = (float *)malloc( len * sizeof( float ) );
127130
for ( i = 0; i < len; i++ ) {
128131
x[ i ] = ( rand_float()*200.0f ) - 100.0f;
129132
}
@@ -139,6 +142,7 @@ static double benchmark2( int iterations, int len ) {
139142
if ( x[ 0 ] != x[ 0 ] ) {
140143
printf( "should not return NaN\n" );
141144
}
145+
free( x );
142146
return elapsed;
143147
}
144148

0 commit comments

Comments
 (0)