Skip to content

Commit 28a47b4

Browse files
committed
bench: update snippet to use dynamic memory allocation
1 parent 5e81b1b commit 28a47b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/snippets/benchmark/c/native/benchmark.length.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
static void print_version( void );
3636
static void print_summary( int total, int passing );
37-
static void print_results( double elapsed );
37+
static void print_results( int iterations, double elapsed );
3838
static double tic( void );
3939
static float rand_float( void );
4040
static double rand_double( void );
@@ -117,11 +117,12 @@ static double rand_double( void ) {
117117
*/
118118
static double benchmark( int iterations, int len ) {
119119
double elapsed;
120-
double x[ len ];
120+
double *x;
121121
double y;
122122
double t;
123123
int i;
124124

125+
x = (double *) malloc( len * sizeof( double ) );
125126
for ( i = 0; i < len; i++ ) {
126127
x[ i ] = ( rand_double()*20000.0 ) - 10000.0;
127128
}
@@ -137,6 +138,7 @@ static double benchmark( int iterations, int len ) {
137138
if ( TODO ) {
138139
printf( "unexpected return value\n" );
139140
}
141+
free( x );
140142
return elapsed;
141143
}
142144

0 commit comments

Comments
 (0)