Skip to content

Commit 4669c51

Browse files
ivishal-gkgryte
andauthored
bench: refactor to use dynamic memory allocation in stats/strided/dmskmin
PR-URL: #9652 Ref: #8643 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 411353c commit 4669c51

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "stdlib/stats/strided/dmskmin.h"
2020
#include <stdlib.h>
21+
#include <stdint.h>
2122
#include <stdio.h>
2223
#include <math.h>
2324
#include <time.h>
@@ -95,13 +96,15 @@ static double rand_double( void ) {
9596
* @return elapsed time in seconds
9697
*/
9798
static double benchmark1( int iterations, int len ) {
98-
unsigned char mask[ len ];
9999
double elapsed;
100-
double x[ len ];
100+
uint8_t *mask;
101+
double *x;
101102
double v;
102103
double t;
103104
int i;
104105

106+
x = (double *) malloc( len * sizeof( double ) );
107+
mask = (uint8_t *) malloc( len * sizeof( uint8_t ) );
105108
for ( i = 0; i < len; i++ ) {
106109
if ( rand_double() < 0.2 ) {
107110
mask[ i ] = 1; // missing
@@ -124,6 +127,8 @@ static double benchmark1( int iterations, int len ) {
124127
if ( v != v ) {
125128
printf( "should not return NaN\n" );
126129
}
130+
free( x );
131+
free( mask );
127132
return elapsed;
128133
}
129134

@@ -135,13 +140,15 @@ static double benchmark1( int iterations, int len ) {
135140
* @return elapsed time in seconds
136141
*/
137142
static double benchmark2( int iterations, int len ) {
138-
unsigned char mask[ len ];
139143
double elapsed;
140-
double x[ len ];
144+
uint8_t *mask;
145+
double *x;
141146
double v;
142147
double t;
143148
int i;
144149

150+
x = (double *) malloc( len * sizeof( double ) );
151+
mask = (uint8_t *) malloc( len * sizeof( uint8_t ) );
145152
for ( i = 0; i < len; i++ ) {
146153
if ( rand_double() < 0.2 ) {
147154
mask[ i ] = 1; // missing
@@ -164,6 +171,8 @@ static double benchmark2( int iterations, int len ) {
164171
if ( v != v ) {
165172
printf( "should not return NaN\n" );
166173
}
174+
free( x );
175+
free( mask );
167176
return elapsed;
168177
}
169178

0 commit comments

Comments
 (0)