From 5fcaef8c0c718064fc3dfb9439b4e90242ec5436 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 1 Jul 2026 12:22:29 +0000 Subject: [PATCH] style: align `stats/base/dists/anglit/quantile` C benchmark with sibling packages Add missing function documentation comments and use the `y != y` self-comparison idiom for NaN checks (dropping the now-unused `` include), matching the C benchmark scaffold used by the other stats/base/dists packages added in this window (poisson/entropy, lognormal/logpdf, log-logistic/pdf). --- .../anglit/quantile/benchmark/c/benchmark.c | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/quantile/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/anglit/quantile/benchmark/c/benchmark.c index 03948f67dc0d..d7140b275aac 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/anglit/quantile/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/quantile/benchmark/c/benchmark.c @@ -19,7 +19,6 @@ #include "stdlib/stats/base/dists/anglit/quantile.h" #include #include -#include #include #include @@ -27,19 +26,33 @@ #define ITERATIONS 1000000 #define REPEATS 3 +/** +* Prints the TAP version. +*/ static void print_version( void ) { printf( "TAP version 13\n" ); } +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ static void print_summary( int total, int passing ) { printf( "#\n" ); - printf( "1..%d\n", total ); + printf( "1..%d\n", total ); // TAP plan printf( "# total %d\n", total ); printf( "# pass %d\n", passing ); printf( "#\n" ); printf( "# ok\n" ); } +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ static void print_results( double elapsed ) { double rate = (double)ITERATIONS / elapsed; printf( " ---\n" ); @@ -49,17 +62,34 @@ static void print_results( double elapsed ) { printf( " ...\n" ); } +/** +* Returns a clock time. +* +* @return clock time +*/ static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); return min + ( v*(max-min) ); } +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ static double benchmark( void ) { double sigma[ 100 ]; double mu[ 100 ]; @@ -78,23 +108,27 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { y = stdlib_base_dists_anglit_quantile( p[ i % 100 ], mu[ i % 100 ], sigma[ i % 100 ] ); - if ( isnan( y ) ) { + if ( y != y ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( isnan( y ) ) { + if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; } +/** +* Main execution sequence. +*/ int main( void ) { double elapsed; int i; + // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); @@ -102,7 +136,7 @@ int main( void ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); - printf( "ok %d benchmark finished\n", i + 1 ); + printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); }