From bd70627bd422054566a274e6fdb6ad711b4d3960 Mon Sep 17 00:00:00 2001 From: Uday Kakade Date: Tue, 21 Apr 2026 18:26:56 +0530 Subject: [PATCH] bench: refactor to use dynamic memory allocation in blas/ext/base/* --- .../scusumkbn/benchmark/c/benchmark.length.c | 16 ++++++++++++---- .../scusumkbn2/benchmark/c/benchmark.length.c | 14 ++++++++++---- .../snancount/benchmark/c/benchmark.length.c | 8 ++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/c/benchmark.length.c index 7a00351ca445..b20698531593 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn/benchmark/c/benchmark.length.c @@ -96,11 +96,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len ]; - float y[ len ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * sizeof( float ) ); + y = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; y[ i ] = 0.0f; @@ -118,6 +120,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; } @@ -130,11 +134,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len ]; - float y[ len ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * sizeof( float ) ); + y = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; y[ i ] = 0.0f; @@ -152,6 +158,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; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/c/benchmark.length.c index 604f38573a6a..8ec2f6d0ee92 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/scusumkbn2/benchmark/c/benchmark.length.c @@ -96,11 +96,13 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len ]; - float y[ len ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * sizeof( float ) ); + y = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; y[ i ] = 0.0f; @@ -130,11 +132,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len ]; - float y[ len ]; + float *x; + float *y; double t; int i; + x = (float *) malloc( len * sizeof( float ) ); + y = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; y[ i ] = 0.0f; @@ -152,6 +156,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; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancount/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/snancount/benchmark/c/benchmark.length.c index ec0d03b9e73e..0fafb5cddfe7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snancount/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/snancount/benchmark/c/benchmark.length.c @@ -96,11 +96,12 @@ static float rand_float( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - float x[ len ]; + float *x; double t; int v; int i; + x = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { if ( rand_float() < 0.2f ) { x[ i ] = 0.0f / 0.0f; // NaN @@ -122,6 +123,7 @@ static double benchmark1( int iterations, int len ) { if ( v < 0 ) { printf( "should return a non-negative integer\n" ); } + free( x ); return elapsed; } @@ -134,11 +136,12 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len ]; + float *x; double t; int v; int i; + x = (float *) malloc( len * sizeof( float ) ); for ( i = 0; i < len; i++ ) { if ( rand_float() < 0.2f ) { x[ i ] = 0.0f / 0.0f; // NaN @@ -160,6 +163,7 @@ static double benchmark2( int iterations, int len ) { if ( v < 0 ) { printf( "should return a non-negative integer\n" ); } + free( x ); return elapsed; }