Skip to content

Commit ad10b3f

Browse files
bench: refactor to use dynamic memory allocation in blas/base/caxpy
1 parent d2b02fe commit ad10b3f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ static float rand_float( void ) {
9797
*/
9898
static double benchmark1( int iterations, int len ) {
9999
stdlib_complex64_t alpha;
100-
float x[ len*2 ];
101-
float y[ len*2 ];
100+
float *x;
101+
float *y;
102102
double elapsed;
103103
double t;
104104
int i;
105105

106106
alpha = stdlib_complex64( 1.0f, 0.0f );
107+
x = (float *) malloc( len * 2 * sizeof( float ) );
108+
y = (float *) malloc( len * 2 * sizeof( float ) );
107109
for ( i = 0; i < len*2; i += 2 ) {
108110
x[ i ] = ( rand_float()*2.0f ) - 1.0f;
109111
x[ i+1 ] = ( rand_float()*2.0f ) - 1.0f;
@@ -122,6 +124,8 @@ static double benchmark1( int iterations, int len ) {
122124
if ( y[ 0 ] != y[ 0 ] ) {
123125
printf( "should not return NaN\n" );
124126
}
127+
free( x );
128+
free( y );
125129
return elapsed;
126130
}
127131

@@ -134,13 +138,15 @@ static double benchmark1( int iterations, int len ) {
134138
*/
135139
static double benchmark2( int iterations, int len ) {
136140
stdlib_complex64_t alpha;
137-
float x[ len*2 ];
138-
float y[ len*2 ];
141+
float *x;
142+
float *y;
139143
double elapsed;
140144
double t;
141145
int i;
142146

143147
alpha = stdlib_complex64( 1.0f, 0.0f );
148+
x = (float *) malloc( len * 2 * sizeof( float ) );
149+
y = (float *) malloc( len * 2 * sizeof( float ) );
144150
for ( i = 0; i < len*2; i += 2 ) {
145151
x[ i ] = ( rand_float()*2.0f ) - 1.0f;
146152
x[ i+1 ] = ( rand_float()*2.0f ) - 1.0f;
@@ -159,6 +165,8 @@ static double benchmark2( int iterations, int len ) {
159165
if ( y[ 0 ] != y[ 0 ] ) {
160166
printf( "should not return NaN\n" );
161167
}
168+
free( x );
169+
free( y );
162170
return elapsed;
163171
}
164172

0 commit comments

Comments
 (0)