Skip to content

Commit 89624b3

Browse files
Faraz GhaniFaraz Ghani
authored andcommitted
bench: refactor to use dynamic memory allocation in blas/base/drot
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 87bfa26 commit 89624b3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ static double rand_double( void ) {
9696
*/
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
99-
double x[ len ];
100-
double y[ len ];
99+
double *x;
100+
double *y;
101101
double t;
102102
int i;
103103

104+
x = (double *) malloc( len * sizeof( double ) );
105+
y = (double *) malloc( len * sizeof( double ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_double()*200.0 ) - 100.0;
106108
y[ i ] = ( rand_double()*200.0 ) - 100.0;
@@ -117,6 +119,9 @@ static double benchmark1( int iterations, int len ) {
117119
if ( y[ 0 ] != y[ 0 ] ) {
118120
printf( "should not return NaN\n" );
119121
}
122+
123+
free( x );
124+
free( y );
120125
return elapsed;
121126
}
122127

@@ -129,11 +134,14 @@ static double benchmark1( int iterations, int len ) {
129134
*/
130135
static double benchmark2( int iterations, int len ) {
131136
double elapsed;
132-
double x[ len ];
133-
double y[ len ];
137+
double *x;
138+
double *y;
134139
double t;
135140
int i;
136141

142+
x = (double *) malloc( len * sizeof( double ) );
143+
y = (double *) malloc( len * sizeof( double ) );
144+
137145
for ( i = 0; i < len; i++ ) {
138146
x[ i ] = ( rand_double()*200.0 ) - 100.0;
139147
y[ i ] = ( rand_double()*200.0 ) - 100.0;
@@ -150,6 +158,10 @@ static double benchmark2( int iterations, int len ) {
150158
if ( y[ 0 ] != y[ 0 ] ) {
151159
printf( "should not return NaN\n" );
152160
}
161+
162+
free( x );
163+
free( y );
164+
153165
return elapsed;
154166
}
155167

0 commit comments

Comments
 (0)