Skip to content

Commit c62573e

Browse files
bench: refactor to use dynamic memory allocation in blas/base/sdot
PR-URL: #10173 Ref: #8643 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 70190d9 commit c62573e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/node_modules/@stdlib/blas/base/sdot/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
float 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;
@@ -120,6 +122,8 @@ static double benchmark1( int iterations, int len ) {
120122
if ( z != z ) {
121123
printf( "should not return NaN\n" );
122124
}
125+
free( x );
126+
free( y );
123127
return elapsed;
124128
}
125129

@@ -132,12 +136,14 @@ static double benchmark1( int iterations, int len ) {
132136
*/
133137
static double benchmark2( int iterations, int len ) {
134138
double elapsed;
135-
float x[ len ];
136-
float y[ len ];
139+
float *x;
140+
float *y;
137141
float z;
138142
double t;
139143
int i;
140144

145+
x = (float *) malloc( len * sizeof( float ) );
146+
y = (float *) malloc( len * sizeof( float ) );
141147
for ( i = 0; i < len; i++ ) {
142148
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
143149
y[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
@@ -156,6 +162,8 @@ static double benchmark2( int iterations, int len ) {
156162
if ( z != z ) {
157163
printf( "should not return NaN\n" );
158164
}
165+
free( x );
166+
free( y );
159167
return elapsed;
160168
}
161169

0 commit comments

Comments
 (0)