Skip to content

Commit 39cae6b

Browse files
authored
bench: use dynamic allocation
Signed-off-by: Athan <kgryte@gmail.com>
1 parent 1347256 commit 39cae6b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 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,14 +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+
uint8_t *mask;
100101
double *x;
101102
double v;
102103
double t;
103104
int i;
104105

105106
x = (double *) malloc( len * sizeof( double ) );
107+
mask = (uint8_t *) malloc( len * sizeof( uint8_t ) );
106108
for ( i = 0; i < len; i++ ) {
107109
if ( rand_double() < 0.2 ) {
108110
mask[ i ] = 1; // missing
@@ -126,6 +128,7 @@ static double benchmark1( int iterations, int len ) {
126128
printf( "should not return NaN\n" );
127129
}
128130
free( x );
131+
free( mask );
129132
return elapsed;
130133
}
131134

@@ -137,14 +140,15 @@ static double benchmark1( int iterations, int len ) {
137140
* @return elapsed time in seconds
138141
*/
139142
static double benchmark2( int iterations, int len ) {
140-
unsigned char mask[ len ];
141143
double elapsed;
144+
uint8_t *mask;
142145
double *x;
143146
double v;
144147
double t;
145148
int i;
146149

147150
x = (double *) malloc( len * sizeof( double ) );
151+
mask = (uint8_t *) malloc( len * sizeof( uint8_t ) );
148152
for ( i = 0; i < len; i++ ) {
149153
if ( rand_double() < 0.2 ) {
150154
mask[ i ] = 1; // missing
@@ -168,6 +172,7 @@ static double benchmark2( int iterations, int len ) {
168172
printf( "should not return NaN\n" );
169173
}
170174
free( x );
175+
free( mask );
171176
return elapsed;
172177
}
173178

0 commit comments

Comments
 (0)