Skip to content

Commit 3fc2ef2

Browse files
bench: refactor csrot benchmark to use dynamic allocation
1 parent 4304bee commit 3fc2ef2

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ static float rand_float( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
float x[ len*2 ];
100-
float y[ len*2 ];
99+
float *x;
100+
float *y;
101101
double t;
102102
int i;
103-
103+
x = (float *)malloc( len * 2 * sizeof(float) );
104+
y = (float *)malloc( len * 2 * sizeof(float) );
104105
for ( i = 0; i < len; i++ ) {
105106
x[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
106107
x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
@@ -119,6 +120,8 @@ static double benchmark1( int iterations, int len ) {
119120
if ( y[ 0 ] != y[ 0 ] ) {
120121
printf( "should not return NaN\n" );
121122
}
123+
free( x );
124+
free( y );
122125
return elapsed;
123126
}
124127

@@ -131,11 +134,14 @@ static double benchmark1( int iterations, int len ) {
131134
*/
132135
static double benchmark2( int iterations, int len ) {
133136
double elapsed;
134-
float x[ len*2 ];
135-
float y[ len*2 ];
137+
float *x;
138+
float *y;
136139
double t;
137140
int i;
138141

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

0 commit comments

Comments
 (0)