Skip to content

Commit 1a5b206

Browse files
committed
perf:replace static memory allocation of large arrays in C benchmarks with dynamic memory allocation
1 parent 6838830 commit 1a5b206

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ 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
float v;
101101
double t;
102102
int i;
103-
103+
x = (float *) malloc( len * sizeof( double ) );
104104
for ( i = 0; i < len; i++ ) {
105105
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
106106
}
@@ -118,6 +118,7 @@ static double benchmark1( int iterations, int len ) {
118118
if ( v != v ) {
119119
printf( "should not return NaN\n" );
120120
}
121+
free(x);
121122
return elapsed;
122123
}
123124

@@ -130,11 +131,11 @@ static double benchmark1( int iterations, int len ) {
130131
*/
131132
static double benchmark2( int iterations, int len ) {
132133
double elapsed;
133-
float x[ len ];
134+
float *x;
134135
float v;
135136
double t;
136137
int i;
137-
138+
x = (float *) malloc( len * sizeof( double ) );
138139
for ( i = 0; i < len; i++ ) {
139140
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
140141
}
@@ -152,6 +153,7 @@ static double benchmark2( int iterations, int len ) {
152153
if ( v != v ) {
153154
printf( "should not return NaN\n" );
154155
}
156+
free(x);
155157
return elapsed;
156158
}
157159

0 commit comments

Comments
 (0)