Skip to content

Commit a4c852e

Browse files
authored
bench: refactor to use dynamic memory allocation
PR-URL: #9213 Ref: #8643 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 3633d58 commit a4c852e

File tree

1 file changed

+18
-6
lines changed
  • lib/node_modules/@stdlib/blas/base/dsyr2/benchmark/c

1 file changed

+18
-6
lines changed

lib/node_modules/@stdlib/blas/base/dsyr2/benchmark/c/benchmark.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ static double tic( void ) {
8888
*/
8989
static double benchmark1( int iterations, int N ) {
9090
double elapsed;
91-
double A[ N*N ];
92-
double x[ N ];
93-
double y[ N ];
91+
double *A;
92+
double *x;
93+
double *y;
9494
double t;
9595
int i;
9696

97+
x = (double *)malloc( N * sizeof( double ) );
98+
y = (double *)malloc( N * sizeof( double ) );
99+
A = (double *)malloc( N * N * sizeof( double ) );
97100
stdlib_strided_dfill( N, 1.0, x, 1 );
98101
stdlib_strided_dfill( N, 1.0, y, 1 );
99102
stdlib_strided_dfill( N*N, 1.0, A, 1 );
@@ -109,6 +112,9 @@ static double benchmark1( int iterations, int N ) {
109112
if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) {
110113
printf( "should not return NaN\n" );
111114
}
115+
free( x );
116+
free( y );
117+
free( A );
112118
return elapsed;
113119
}
114120

@@ -121,12 +127,15 @@ static double benchmark1( int iterations, int N ) {
121127
*/
122128
static double benchmark2( int iterations, int N ) {
123129
double elapsed;
124-
double A[ N*N ];
125-
double x[ N ];
126-
double y[ N ];
130+
double *A;
131+
double *x;
132+
double *y;
127133
double t;
128134
int i;
129135

136+
x = (double *)malloc( N * sizeof( double ) );
137+
y = (double *)malloc( N * sizeof( double ) );
138+
A = (double *)malloc( N * N * sizeof( double ) );
130139
stdlib_strided_dfill( N, 1.0, x, 1 );
131140
stdlib_strided_dfill( N, 1.0, y, 1 );
132141
stdlib_strided_dfill( N*N, 1.0, A, 1 );
@@ -142,6 +151,9 @@ static double benchmark2( int iterations, int N ) {
142151
if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) {
143152
printf( "should not return NaN\n" );
144153
}
154+
free( x );
155+
free( y );
156+
free( A );
145157
return elapsed;
146158
}
147159

0 commit comments

Comments
 (0)