Skip to content

Commit 295aca6

Browse files
committed
refactor: convert static to dynamic allocation in benchmark1 and benchmark2
Signed-off-by: Yohan Park <88149844+yohan9569@users.noreply.github.com>
1 parent 9e5f4c4 commit 295aca6

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

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

Lines changed: 13 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,9 @@ static double benchmark1( int iterations, int len ) {
119121
if ( z != z ) {
120122
printf( "should not return NaN\n" );
121123
}
124+
125+
free( x );
126+
free( y );
122127
return elapsed;
123128
}
124129

@@ -131,12 +136,14 @@ static double benchmark1( int iterations, int len ) {
131136
*/
132137
static double benchmark2( int iterations, int len ) {
133138
double elapsed;
134-
float x[ len ];
135-
float y[ len ];
139+
float *x;
140+
float *y;
136141
double z;
137142
double t;
138143
int i;
139144

145+
x = (float *) malloc( len * sizeof( float ) );
146+
y = (float *) malloc( len * sizeof( float ) );
140147
for ( i = 0; i < len; i++ ) {
141148
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
142149
y[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
@@ -154,6 +161,8 @@ static double benchmark2( int iterations, int len ) {
154161
if ( z != z ) {
155162
printf( "should not return NaN\n" );
156163
}
164+
free( x );
165+
free( y );
157166
return elapsed;
158167
}
159168

0 commit comments

Comments
 (0)