Skip to content

Commit d951f44

Browse files
authored
bench: refactor to use dynamic memory allocation in stats/strided/dmaxabssorted
PR-URL: #11676 Ref: #8643 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 7a025ca commit d951f44

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ static double tic( void ) {
8686
*/
8787
static double benchmark1( int iterations, int len ) {
8888
double elapsed;
89-
double x[ len ];
89+
double *x;
9090
double v;
9191
double t;
9292
int i;
9393

94+
x = (double *) malloc( len * sizeof( double ) );
9495
for ( i = 0; i < len; i++ ) {
9596
x[ i ] = i - (len/2);
9697
}
@@ -108,6 +109,7 @@ static double benchmark1( int iterations, int len ) {
108109
if ( v != v ) {
109110
printf( "should not return NaN\n" );
110111
}
112+
free( x );
111113
return elapsed;
112114
}
113115

@@ -120,11 +122,12 @@ static double benchmark1( int iterations, int len ) {
120122
*/
121123
static double benchmark2( int iterations, int len ) {
122124
double elapsed;
123-
double x[ len ];
125+
double *x;
124126
double v;
125127
double t;
126128
int i;
127129

130+
x = (double *) malloc( len * sizeof( double ) );
128131
for ( i = 0; i < len; i++ ) {
129132
x[ i ] = i - (len/2);
130133
}
@@ -142,6 +145,7 @@ static double benchmark2( int iterations, int len ) {
142145
if ( v != v ) {
143146
printf( "should not return NaN\n" );
144147
}
148+
free( x );
145149
return elapsed;
146150
}
147151

0 commit comments

Comments
 (0)