Skip to content

Commit 32d9f09

Browse files
Omar-2718kgryte
andauthored
bench: refactor to use dynamic memory allocation in strided/base/smskmap2
PR-URL: #9350 Ref: #8643 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 51b40f8 commit 32d9f09

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/node_modules/@stdlib/strided/base/smskmap2/benchmark/c/benchmark.length.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,18 @@ static float addf( const float x, const float y ) {
107107
* @return elapsed time in seconds
108108
*/
109109
static double benchmark( int iterations, int len ) {
110-
uint8_t m[ len ];
111110
double elapsed;
112-
float x[ len ];
113-
float y[ len ];
114-
float z[ len ];
111+
uint8_t *m;
112+
float *x;
113+
float *y;
114+
float *z;
115115
double t;
116116
int i;
117117

118+
m = (uint8_t *)malloc( len * sizeof( uint8_t ) );
119+
x = (float *)malloc( len * sizeof( float ) );
120+
y = (float *)malloc( len * sizeof( float ) );
121+
z = (float *)malloc( len * sizeof( float ) );
118122
for ( i = 0; i < len; i++ ) {
119123
x[ i ] = ( rand_float()*200.0f ) - 100.0f;
120124
y[ i ] = ( rand_float()*200.0f ) - 100.0f;
@@ -133,6 +137,10 @@ static double benchmark( int iterations, int len ) {
133137
if ( z[ i%len ] != z[ i%len ] ) {
134138
printf( "should not return NaN\n" );
135139
}
140+
free( m );
141+
free( x );
142+
free( y );
143+
free( z );
136144
return elapsed;
137145
}
138146

0 commit comments

Comments
 (0)