Skip to content

Commit c354cf2

Browse files
Faraz GhaniFaraz Ghani
authored andcommitted
bench: refactor to use dynamic memory allocation in blas/base/dcopy
--- 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 89624b3 commit c354cf2

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ 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 ) );
106+
104107
for ( i = 0; i < len; i++ ) {
105108
x[ i ] = ( rand_double()*20000.0 ) - 10000.0;
106109
y[ i ] = 0.0;
@@ -117,6 +120,9 @@ static double benchmark1( int iterations, int len ) {
117120
if ( y[ 0 ] != y[ 0 ] ) {
118121
printf( "should not return NaN\n" );
119122
}
123+
124+
free( x );
125+
free( y );
120126
return elapsed;
121127
}
122128

@@ -129,11 +135,13 @@ static double benchmark1( int iterations, int len ) {
129135
*/
130136
static double benchmark2( int iterations, int len ) {
131137
double elapsed;
132-
double x[ len ];
133-
double y[ len ];
138+
double *x;
139+
double *y;
134140
double t;
135141
int i;
136142

143+
x = (double *) malloc( len * sizeof( double ) );
144+
y = (double *) malloc( len * sizeof( double ) );
137145
for ( i = 0; i < len; i++ ) {
138146
x[ i ] = ( rand_double()*20000.0 ) - 10000.0;
139147
y[ i ] = 0.0;
@@ -150,6 +158,8 @@ static double benchmark2( int iterations, int len ) {
150158
if ( y[ 0 ] != y[ 0 ] ) {
151159
printf( "should not return NaN\n" );
152160
}
161+
free( x );
162+
free( y );
153163
return elapsed;
154164
}
155165

0 commit comments

Comments
 (0)