From 201d4442f2dcf89b30b7aee39710f873096585c8 Mon Sep 17 00:00:00 2001 From: kshitijgarg2811-oss Date: Thu, 1 Jan 2026 16:54:28 +0530 Subject: [PATCH 1/3] bench: refactor to use dynamic memory allocation in math/strided/special/strunc --- .../strunc/benchmark/c/benchmark.length.c | 160 ++++++++++-------- 1 file changed, 89 insertions(+), 71 deletions(-) diff --git a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c index c6da372d28b0..c2facea5cc73 100644 --- a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c @@ -7,7 +7,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ * Prints the TAP version. */ static void print_version( void ) { - printf( "TAP version 13\n" ); + printf( "TAP version 13\n" ); } /** @@ -43,12 +43,12 @@ static void print_version( void ) { * @param passing total number of passing tests */ static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); } /** @@ -58,12 +58,12 @@ static void print_summary( int total, int passing ) { * @param elapsed elapsed time in seconds */ static void print_results( int iterations, double elapsed ) { - double rate = (double)iterations / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", iterations ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); } /** @@ -72,9 +72,9 @@ static void print_results( int iterations, double elapsed ) { * @return clock time */ static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** @@ -85,13 +85,13 @@ static double tic( void ) { * @return random number */ double rand_uniform( double a, double b ) { - double x; - int r; + double x; + int r; - r = rand(); - x = (double)r / ( (double)RAND_MAX + 1.0 ); + r = rand(); + x = (double)r / ( (double)RAND_MAX + 1.0 ); - return ( b*x ) + ( (1.0-x)*a ); + return ( b*x ) + ( (1.0-x)*a ); } /** @@ -102,7 +102,7 @@ double rand_uniform( double a, double b ) { * @return random number */ float rand_uniformf( float a, float b ) { - return (float)rand_uniform( (double)a, (double)b ); + return (float)rand_uniform( (double)a, (double)b ); } /** @@ -113,57 +113,75 @@ float rand_uniformf( float a, float b ) { * @return elapsed time in seconds */ static double benchmark( int iterations, int len ) { - double elapsed; - float x[ len ]; - float y[ len ]; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = rand_uniformf( -10.0f, 10.0f ); - y[ i ] = 0.0f; - } - t = tic(); - for ( i = 0; i < iterations; i++ ) { - stdlib_strided_strunc( len, x, 1, y, 1 ); - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } - return elapsed; + double elapsed; + float *x; + float *y; + double t; + int i; + + x = (float *)malloc( len * sizeof( float ) ); + y = (float *)malloc( len * sizeof( float ) ); + + if ( x == NULL || y == NULL ) { + if ( x != NULL ) { + free( x ); + } + if ( y != NULL ) { + free( y ); + } + printf( "Error: unable to allocate memory.\n" ); + exit( 1 ); + } + + for ( i = 0; i < len; i++ ) { + x[ i ] = rand_uniformf( -10.0f, 10.0f ); + y[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_strunc( len, x, 1, y, 1 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + + free( x ); + free( y ); + + return elapsed; } /** * Main execution sequence. */ int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} \ No newline at end of file From 79d2a6e86b15943eed3e86fdc762120499c8dd9e Mon Sep 17 00:00:00 2001 From: kshitijgarg2811-oss Date: Thu, 1 Jan 2026 18:11:51 +0530 Subject: [PATCH 2/3] style: use tabs and remove null check --- .../strunc/benchmark/c/benchmark.length.c | 178 +++++++++--------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c index c2facea5cc73..26bde725dfa1 100644 --- a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c @@ -7,7 +7,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ * Prints the TAP version. */ static void print_version( void ) { - printf( "TAP version 13\n" ); + printf( "TAP version 13\n" ); } /** @@ -43,12 +43,12 @@ static void print_version( void ) { * @param passing total number of passing tests */ static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); } /** @@ -58,12 +58,12 @@ static void print_summary( int total, int passing ) { * @param elapsed elapsed time in seconds */ static void print_results( int iterations, double elapsed ) { - double rate = (double)iterations / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", iterations ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); } /** @@ -72,9 +72,9 @@ static void print_results( int iterations, double elapsed ) { * @return clock time */ static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** @@ -85,13 +85,13 @@ static double tic( void ) { * @return random number */ double rand_uniform( double a, double b ) { - double x; - int r; + double x; + int r; - r = rand(); - x = (double)r / ( (double)RAND_MAX + 1.0 ); + r = rand(); + x = (double)r / ( (double)RAND_MAX + 1.0 ); - return ( b*x ) + ( (1.0-x)*a ); + return ( b*x ) + ( (1.0-x)*a ); } /** @@ -102,7 +102,7 @@ double rand_uniform( double a, double b ) { * @return random number */ float rand_uniformf( float a, float b ) { - return (float)rand_uniform( (double)a, (double)b ); + return (float)rand_uniform( (double)a, (double)b ); } /** @@ -113,75 +113,75 @@ float rand_uniformf( float a, float b ) { * @return elapsed time in seconds */ static double benchmark( int iterations, int len ) { - double elapsed; - float *x; - float *y; - double t; - int i; - - x = (float *)malloc( len * sizeof( float ) ); - y = (float *)malloc( len * sizeof( float ) ); - - if ( x == NULL || y == NULL ) { - if ( x != NULL ) { - free( x ); - } - if ( y != NULL ) { - free( y ); - } - printf( "Error: unable to allocate memory.\n" ); - exit( 1 ); - } - - for ( i = 0; i < len; i++ ) { - x[ i ] = rand_uniformf( -10.0f, 10.0f ); - y[ i ] = 0.0f; - } - t = tic(); - for ( i = 0; i < iterations; i++ ) { - stdlib_strided_strunc( len, x, 1, y, 1 ); - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } - - free( x ); - free( y ); - - return elapsed; + double elapsed; + float *x; + float *y; + double t; + int i; + + x = (float *)malloc( len * sizeof( float ) ); + y = (float *)malloc( len * sizeof( float ) ); + + if (x == NULL || y == NULL ) { + if ( x != NULL ) { + free( x ); + } + if ( y != NULL ) { + free( y ); + } + printf("Error: unable to allocate memory.\n"); + exit( 1 ); + } + + for ( i = 0; i < len; i++ ) { + x[ i ] = rand_uniformf( -10.0f, 10.0f ); + y[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_strunc( len, x, 1, y, 1 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + + free( x ); + free( y ); + + return elapsed; } /** * Main execution sequence. */ int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} \ No newline at end of file + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} From 1731b27c3b95581671c735f77f7aefcc362d6306 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 2 Jan 2026 00:00:09 -0800 Subject: [PATCH 3/3] bench: clean-up Signed-off-by: Athan --- .../special/strunc/benchmark/c/benchmark.length.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c index 26bde725dfa1..ea3aaf920d97 100644 --- a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c @@ -121,18 +121,6 @@ static double benchmark( int iterations, int len ) { x = (float *)malloc( len * sizeof( float ) ); y = (float *)malloc( len * sizeof( float ) ); - - if (x == NULL || y == NULL ) { - if ( x != NULL ) { - free( x ); - } - if ( y != NULL ) { - free( y ); - } - printf("Error: unable to allocate memory.\n"); - exit( 1 ); - } - for ( i = 0; i < len; i++ ) { x[ i ] = rand_uniformf( -10.0f, 10.0f ); y[ i ] = 0.0f; @@ -149,10 +137,8 @@ static double benchmark( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } - free( x ); free( y ); - return elapsed; }