Skip to content

Commit efec547

Browse files
bhargava-d16kgryte
andauthored
bench: refactor to use dynamic memory allocation in stats/strided/dnanmeanwd
PR-URL: #9657 Ref: #8643 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 676581b commit efec547

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/node_modules/@stdlib/stats/strided/dnanmeanwd/benchmark/c/benchmark.length.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ static double rand_double( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
double x[ len ];
99+
double *x;
100100
double v;
101101
double t;
102102
int i;
103103

104+
x = (double *) malloc( len * sizeof( double ) );
104105
for ( i = 0; i < len; i++ ) {
105106
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
106107
}
@@ -118,6 +119,7 @@ static double benchmark1( int iterations, int len ) {
118119
if ( v != v ) {
119120
printf( "should not return NaN\n" );
120121
}
122+
free( x );
121123
return elapsed;
122124
}
123125

@@ -130,11 +132,12 @@ static double benchmark1( int iterations, int len ) {
130132
*/
131133
static double benchmark2( int iterations, int len ) {
132134
double elapsed;
133-
double x[ len ];
135+
double *x;
134136
double v;
135137
double t;
136138
int i;
137139

140+
x = (double *) malloc( len * sizeof( double ) );
138141
for ( i = 0; i < len; i++ ) {
139142
if ( rand_double() < 0.2 ) {
140143
x[ i ] = 0.0 / 0.0; // NaN
@@ -156,6 +159,7 @@ static double benchmark2( int iterations, int len ) {
156159
if ( v != v ) {
157160
printf( "should not return NaN\n" );
158161
}
162+
free( x );
159163
return elapsed;
160164
}
161165

0 commit comments

Comments
 (0)