Skip to content

Commit 7165512

Browse files
committed
bench: refactor to use dynamic memory allocation in dasumpw
Ref: #8643
1 parent baaed47 commit 7165512

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include <sys/time.h>
1920
#include "stdlib/blas/ext/base/dasumpw.h"
20-
#include <stdlib.h>
21-
#include <stdio.h>
2221
#include <math.h>
22+
#include <stdio.h>
23+
#include <stdlib.h>
2324
#include <time.h>
24-
#include <sys/time.h>
2525

2626
#define NAME "dasumpw"
2727
#define ITERATIONS 1000000
@@ -74,7 +74,7 @@ static void print_results( int iterations, double elapsed ) {
7474
static double tic( void ) {
7575
struct timeval now;
7676
gettimeofday( &now, NULL );
77-
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
77+
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
7878
}
7979

8080
/**
@@ -96,10 +96,11 @@ static double rand_double( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
double x[ len ];
99+
double *x;
100100
double v;
101101
double t;
102102
int i;
103+
x = (double *)malloc( len * sizeof( double ) );
103104

104105
for ( i = 0; i < len; i++ ) {
105106
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
@@ -118,6 +119,7 @@ static double benchmark1( int iterations, int len ) {
118119
if ( v != v ) {
119120
printf( "should not return NaN\n" );
120121
}
122+
free( x );
121123
return elapsed;
122124
}
123125

@@ -130,10 +132,11 @@ static double benchmark1( int iterations, int len ) {
130132
*/
131133
static double benchmark2( int iterations, int len ) {
132134
double elapsed;
133-
double x[ len ];
135+
double *x;
134136
double v;
135137
double t;
136138
int i;
139+
x = (double *)malloc( len * sizeof( double ) );
137140

138141
for ( i = 0; i < len; i++ ) {
139142
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
@@ -152,6 +155,7 @@ static double benchmark2( int iterations, int len ) {
152155
if ( v != v ) {
153156
printf( "should not return NaN\n" );
154157
}
158+
free( x );
155159
return elapsed;
156160
}
157161

@@ -173,7 +177,7 @@ int main( void ) {
173177
count = 0;
174178
for ( i = MIN; i <= MAX; i++ ) {
175179
len = pow( 10, i );
176-
iter = ITERATIONS / pow( 10, i-1 );
180+
iter = ITERATIONS / pow( 10, i - 1 );
177181
for ( j = 0; j < REPEATS; j++ ) {
178182
count += 1;
179183
printf( "# c::%s:len=%d\n", NAME, len );
@@ -184,7 +188,7 @@ int main( void ) {
184188
}
185189
for ( i = MIN; i <= MAX; i++ ) {
186190
len = pow( 10, i );
187-
iter = ITERATIONS / pow( 10, i-1 );
191+
iter = ITERATIONS / pow( 10, i - 1 );
188192
for ( j = 0; j < REPEATS; j++ ) {
189193
count += 1;
190194
printf( "# c::%s:ndarray:len=%d\n", NAME, len );

0 commit comments

Comments
 (0)