Skip to content

Commit 8740037

Browse files
bench: refactor to use dynamic memory allocation in /blas/ext/base/dnancusumkbn
Replace static memory allocation in C benchmark in /blas/ext/base/dnancusumkbn with dynamic memory allocation --- 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: passed - 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 6f4927c commit 8740037

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 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
if ( rand_double() < 0.2 ) {
106109
x[ i ] = 0.0 / 0.0; // NaN
@@ -122,6 +125,8 @@ static double benchmark1( int iterations, int len ) {
122125
if ( y[ len-1 ] != y[ len-1 ] ) {
123126
printf( "should not return NaN\n" );
124127
}
128+
free(x);
129+
free(y);
125130
return elapsed;
126131
}
127132

@@ -134,11 +139,13 @@ static double benchmark1( int iterations, int len ) {
134139
*/
135140
static double benchmark2( int iterations, int len ) {
136141
double elapsed;
137-
double x[ len ];
138-
double y[ len ];
142+
double *x;
143+
double *y;
139144
double t;
140145
int i;
141146

147+
x = (double *) malloc( len * sizeof( double ) );
148+
y = (double *) malloc( len * sizeof( double ) );
142149
for ( i = 0; i < len; i++ ) {
143150
if ( rand_double() < 0.2 ) {
144151
x[ i ] = 0.0 / 0.0; // NaN
@@ -160,6 +167,8 @@ static double benchmark2( int iterations, int len ) {
160167
if ( y[ len-1 ] != y[ len-1 ] ) {
161168
printf( "should not return NaN\n" );
162169
}
170+
free(x);
171+
free(y);
163172
return elapsed;
164173
}
165174

0 commit comments

Comments
 (0)