Skip to content

Commit e825c5f

Browse files
me0-0Planeshifter
andauthored
bench(dcusum): use dynamic memory allocation
PR-URL: stdlib-js#10209 Ref: stdlib-js#8643 Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent c34c46b commit e825c5f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

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

104+
x = (double *) malloc( len * sizeof( double ) );
105+
y = (double *) malloc( len * sizeof( double ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
106108
y[ i ] = 0.0;
@@ -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-
double x[ len ];
134-
double y[ len ];
137+
double *x;
138+
double *y;
135139
double t;
136140
int i;
137141

142+
x = (double *) malloc( len * sizeof( double ) );
143+
y = (double *) malloc( len * sizeof( double ) );
138144
for ( i = 0; i < len; i++ ) {
139145
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
140146
y[ i ] = 0.0;
@@ -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

0 commit comments

Comments
 (0)