From 87400376999cc9cb966720f009f9b2624a8ee237 Mon Sep 17 00:00:00 2001 From: Sijan Bhandari Date: Mon, 1 Dec 2025 14:25:13 +0545 Subject: [PATCH 1/3] 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 --- --- .../dnancusumkbn/benchmark/c/benchmark.length.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c index b9b1f65f7e4f..889801913f5e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c @@ -96,11 +96,14 @@ static double rand_double( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - double x[ len ]; - double y[ len ]; + double *x; + double *y; double t; int i; + x = (double *) malloc( len * sizeof( double ) ); + y = (double *) malloc( len * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { if ( rand_double() < 0.2 ) { x[ i ] = 0.0 / 0.0; // NaN @@ -122,6 +125,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ len-1 ] != y[ len-1 ] ) { printf( "should not return NaN\n" ); } + free(x); + free(y); return elapsed; } @@ -134,11 +139,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - double x[ len ]; - double y[ len ]; + double *x; + double *y; double t; int i; + x = (double *) malloc( len * sizeof( double ) ); + y = (double *) malloc( len * sizeof( double ) ); for ( i = 0; i < len; i++ ) { if ( rand_double() < 0.2 ) { x[ i ] = 0.0 / 0.0; // NaN @@ -160,6 +167,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ len-1 ] != y[ len-1 ] ) { printf( "should not return NaN\n" ); } + free(x); + free(y); return elapsed; } From 87ccf591af08a86b7c5bf372f97aef930ad092aa Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 03:00:56 -0800 Subject: [PATCH 2/3] style: remove empty line Signed-off-by: Athan --- .../blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c index 889801913f5e..5dbe0be3ac4d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c @@ -103,7 +103,6 @@ static double benchmark1( int iterations, int len ) { x = (double *) malloc( len * sizeof( double ) ); y = (double *) malloc( len * sizeof( double ) ); - for ( i = 0; i < len; i++ ) { if ( rand_double() < 0.2 ) { x[ i ] = 0.0 / 0.0; // NaN From 5ccec21cdbf3672e1ad6451253942d3c2cb930e2 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 03:01:42 -0800 Subject: [PATCH 3/3] Apply suggestions from code review Signed-off-by: Athan --- .../ext/base/dnancusumkbn/benchmark/c/benchmark.length.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c index 5dbe0be3ac4d..e9af1b9e0b50 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c @@ -124,8 +124,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ len-1 ] != y[ len-1 ] ) { printf( "should not return NaN\n" ); } - free(x); - free(y); + free( x ); + free( y ); return elapsed; } @@ -166,8 +166,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ len-1 ] != y[ len-1 ] ) { printf( "should not return NaN\n" ); } - free(x); - free(y); + free( x ); + free( y ); return elapsed; }