Skip to content

Commit c5b700a

Browse files
authored
bench: refactor to use dynamic memory allocation in blas/ext/base
PR-URL: #11695 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #8643
1 parent 6f2e5f6 commit c5b700a

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/c/benchmark.length.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ 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 t;
102102
int i;
103103

104+
x = (float *) malloc( len * sizeof( float ) );
105+
y = (float *) malloc( len * sizeof( float ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f;
106108
y[ i ] = 0.0f;
@@ -118,6 +120,8 @@ static double benchmark1( int iterations, int len ) {
118120
if ( y[ len-1 ] != y[ len-1 ] ) {
119121
printf( "should not return NaN\n" );
120122
}
123+
free( x );
124+
free( y );
121125
return elapsed;
122126
}
123127

@@ -130,11 +134,13 @@ static double benchmark1( int iterations, int len ) {
130134
*/
131135
static double benchmark2( int iterations, int len ) {
132136
double elapsed;
133-
float x[ len ];
134-
float y[ len ];
137+
float *x;
138+
float *y;
135139
double t;
136140
int i;
137141

142+
x = (float *) malloc( len * sizeof( float ) );
143+
y = (float *) malloc( len * sizeof( float ) );
138144
for ( i = 0; i < len; i++ ) {
139145
x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f;
140146
y[ i ] = 0.0f;
@@ -152,6 +158,8 @@ static double benchmark2( int iterations, int len ) {
152158
if ( y[ len-1 ] != y[ len-1 ] ) {
153159
printf( "should not return NaN\n" );
154160
}
161+
free( x );
162+
free( y );
155163
return elapsed;
156164
}
157165

lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/c/benchmark.length.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ 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 t;
102102
int i;
103103

104+
x = (float *) malloc( len * sizeof( float ) );
105+
y = (float *) malloc( len * sizeof( float ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f;
106108
y[ i ] = 0.0f;
@@ -130,11 +132,13 @@ static double benchmark1( int iterations, int len ) {
130132
*/
131133
static double benchmark2( int iterations, int len ) {
132134
double elapsed;
133-
float x[ len ];
134-
float y[ len ];
135+
float *x;
136+
float *y;
135137
double t;
136138
int i;
137139

140+
x = (float *) malloc( len * sizeof( float ) );
141+
y = (float *) malloc( len * sizeof( float ) );
138142
for ( i = 0; i < len; i++ ) {
139143
x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f;
140144
y[ i ] = 0.0f;
@@ -152,6 +156,8 @@ static double benchmark2( int iterations, int len ) {
152156
if ( y[ len-1 ] != y[ len-1 ] ) {
153157
printf( "should not return NaN\n" );
154158
}
159+
free( x );
160+
free( y );
155161
return elapsed;
156162
}
157163

lib/node_modules/@stdlib/blas/ext/base/snancount/benchmark/c/benchmark.length.c

Lines changed: 6 additions & 2 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 ];
99+
float *x;
100100
double t;
101101
int v;
102102
int i;
103103

104+
x = (float *) malloc( len * sizeof( float ) );
104105
for ( i = 0; i < len; i++ ) {
105106
if ( rand_float() < 0.2f ) {
106107
x[ i ] = 0.0f / 0.0f; // NaN
@@ -122,6 +123,7 @@ static double benchmark1( int iterations, int len ) {
122123
if ( v < 0 ) {
123124
printf( "should return a non-negative integer\n" );
124125
}
126+
free( x );
125127
return elapsed;
126128
}
127129

@@ -134,11 +136,12 @@ static double benchmark1( int iterations, int len ) {
134136
*/
135137
static double benchmark2( int iterations, int len ) {
136138
double elapsed;
137-
float x[ len ];
139+
float *x;
138140
double t;
139141
int v;
140142
int i;
141143

144+
x = (float *) malloc( len * sizeof( float ) );
142145
for ( i = 0; i < len; i++ ) {
143146
if ( rand_float() < 0.2f ) {
144147
x[ i ] = 0.0f / 0.0f; // NaN
@@ -160,6 +163,7 @@ static double benchmark2( int iterations, int len ) {
160163
if ( v < 0 ) {
161164
printf( "should return a non-negative integer\n" );
162165
}
166+
free( x );
163167
return elapsed;
164168
}
165169

0 commit comments

Comments
 (0)