From e4f5c98464fdbff394d39a9b42ae8eacfe01d005 Mon Sep 17 00:00:00 2001 From: hrshya Date: Wed, 19 Mar 2025 02:50:28 +0530 Subject: [PATCH] bench: update random value generation --- .../base/special/floor/benchmark/benchmark.js | 12 +++++++----- .../special/floor/benchmark/benchmark.native.js | 7 ++++--- .../base/special/floor/benchmark/c/benchmark.c | 9 ++++++--- .../special/floor/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../special/floor/benchmark/c/native/benchmark.c | 9 ++++++--- .../@stdlib/math/base/special/floor/test/test.js | 10 +++++----- .../math/base/special/floor/test/test.native.js | 10 +++++----- .../base/special/floorf/benchmark/benchmark.js | 16 +++++++++++----- .../special/floorf/benchmark/benchmark.native.js | 9 ++++++--- .../base/special/floorf/benchmark/c/benchmark.c | 9 ++++++--- .../floorf/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../floorf/benchmark/c/native/benchmark.c | 9 ++++++--- .../math/base/special/floorf/test/test.js | 10 +++++----- .../math/base/special/floorf/test/test.native.js | 10 +++++----- 14 files changed, 84 insertions(+), 54 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.js index eb18283321f6..b06405fff417 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var floor = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = floor( x ); + y = floor( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -55,10 +56,11 @@ bench( pkg+'::built-in', function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = Math.floor( x ); // eslint-disable-line stdlib/no-builtin-math + y = Math.floor( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.native.js index a1a5675a6d8a..021a69d0c403 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = floor( x ); + y = floor( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/benchmark.c index 89492a640715..4ba8e68f998d 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/benchmark.c @@ -90,15 +90,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double()*1000.0 ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = floor( x ); + y = floor( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/cephes/benchmark.c index 14787e60dde9..e1a7c68a909c 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/cephes/benchmark.c @@ -95,15 +95,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double()*1000.0 ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = floor( x ); + y = floor( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/native/benchmark.c index 08cd4acb6a98..d2df4a71e3d9 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/native/benchmark.c @@ -91,15 +91,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_floor( x ); + y = stdlib_base_floor( x[ i%100] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floor/test/test.js b/lib/node_modules/@stdlib/math/base/special/floor/test/test.js index ec07ba0224f0..89f80b70cc16 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/floor/test/test.js @@ -46,30 +46,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu tape( 'the function returns `-0` if provided `-0`', function test( t ) { var v = floor( -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+0` if provided `+0`', function test( t ) { var v = floor( +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) { var v = floor( NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { var val = floor( PINF ); - t.strictEqual( val, PINF, 'returns +infinity' ); + t.strictEqual( val, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { var val = floor( NINF ); - t.strictEqual( val, NINF, 'returns -infinity' ); + t.strictEqual( val, NINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/floor/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/floor/test/test.native.js index bb6ce8d23cac..3a2d805dea76 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/floor/test/test.native.js @@ -55,30 +55,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { var v = floor( -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { var v = floor( +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) { var v = floor( NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { var val = floor( PINF ); - t.strictEqual( val, PINF, 'returns +infinity' ); + t.strictEqual( val, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { var val = floor( NINF ); - t.strictEqual( val, NINF, 'returns -infinity' ); + t.strictEqual( val, NINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.js index 0766035c2c52..4122b43c1b96 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var floorf = require( './../lib' ); @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = floorf( x ); + y = floorf( x[ i%x.length ] ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } @@ -55,10 +58,13 @@ bench( pkg+'::built-in', function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = Math.floor( x ); // eslint-disable-line stdlib/no-builtin-math + y = Math.floor( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.native.js index 79f325470ce4..7c7760a1c3f6 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = floorf( x ); + y = floorf( x[ i%x.length ] ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/benchmark.c index 2b5c57178733..20b0b3352b45 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/benchmark.c @@ -91,14 +91,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_float()*1000.0f ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = floorf( x ); + y = floorf( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/cephes/benchmark.c index 9344d71cf9bb..f79244677d02 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/cephes/benchmark.c @@ -96,14 +96,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_float()*1000.0f ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = floorf( x ); + y = floorf( x[ i%100] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/native/benchmark.c index 83db0ed4af2f..bdcbc9e7a713 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/native/benchmark.c @@ -92,14 +92,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_float()*1000.0f ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_floorf( x ); + y = stdlib_base_floorf( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/test/test.js b/lib/node_modules/@stdlib/math/base/special/floorf/test/test.js index 62851a852984..93cf44205898 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/floorf/test/test.js @@ -46,30 +46,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu tape( 'the function returns `-0` if provided `-0`', function test( t ) { var v = floorf( -0.0 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+0` if provided `+0`', function test( t ) { var v = floorf( +0.0 ); - t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) { var v = floorf( NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { var val = floorf( PINF ); - t.strictEqual( val, PINF, 'returns +infinity' ); + t.strictEqual( val, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { var val = floorf( NINF ); - t.strictEqual( val, NINF, 'returns -infinity' ); + t.strictEqual( val, NINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/floorf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/floorf/test/test.native.js index cd11393b1fdd..7e46eb22a2a4 100644 --- a/lib/node_modules/@stdlib/math/base/special/floorf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/floorf/test/test.native.js @@ -55,30 +55,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { var v = floorf( -0.0 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { var v = floorf( +0.0 ); - t.strictEqual( isPositiveZerof( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) { var v = floorf( NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { var val = floorf( PINF ); - t.strictEqual( val, PINF, 'returns +infinity' ); + t.strictEqual( val, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { var val = floorf( NINF ); - t.strictEqual( val, NINF, 'returns -infinity' ); + t.strictEqual( val, NINF, 'returns expected value' ); t.end(); });