Skip to content

Commit 29fc92b

Browse files
yohan9569kgryte
andauthored
bench: refactor to use dynamic memory allocation in blas/base/dsdot
PR-URL: #9309 Ref: #8643 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent bd0b5c8 commit 29fc92b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ static float rand_float( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
float x[ len ];
100-
float y[ len ];
99+
float *x;
100+
float *y;
101101
double z;
102102
double t;
103103
int i;
104104

105+
x = (float *) malloc( len * sizeof( float ) );
106+
y = (float *) malloc( len * sizeof( float ) );
105107
for ( i = 0; i < len; i++ ) {
106108
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
107109
y[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
@@ -119,6 +121,8 @@ static double benchmark1( int iterations, int len ) {
119121
if ( z != z ) {
120122
printf( "should not return NaN\n" );
121123
}
124+
free( x );
125+
free( y );
122126
return elapsed;
123127
}
124128

@@ -131,12 +135,14 @@ static double benchmark1( int iterations, int len ) {
131135
*/
132136
static double benchmark2( int iterations, int len ) {
133137
double elapsed;
134-
float x[ len ];
135-
float y[ len ];
138+
float *x;
139+
float *y;
136140
double z;
137141
double t;
138142
int i;
139143

144+
x = (float *) malloc( len * sizeof( float ) );
145+
y = (float *) malloc( len * sizeof( float ) );
140146
for ( i = 0; i < len; i++ ) {
141147
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
142148
y[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
@@ -154,6 +160,8 @@ static double benchmark2( int iterations, int len ) {
154160
if ( z != z ) {
155161
printf( "should not return NaN\n" );
156162
}
163+
free( x );
164+
free( y );
157165
return elapsed;
158166
}
159167

0 commit comments

Comments
 (0)