From 19cc6693754150a5db828b8ce54b139e4b28cb42 Mon Sep 17 00:00:00 2001 From: hrshya Date: Tue, 15 Apr 2025 14:50:46 +0530 Subject: [PATCH 1/2] bench: update random value generation --- .../assert/is-positive-zerof/benchmark/benchmark.js | 11 ++++++++--- .../is-positive-zerof/benchmark/benchmark.native.js | 11 ++++++++--- .../assert/is-positive-zerof/benchmark/c/benchmark.c | 9 ++++++--- .../is-positive-zerof/benchmark/c/native/benchmark.c | 9 ++++++--- .../math/base/assert/is-positive-zerof/test/test.js | 8 ++++---- .../base/assert/is-positive-zerof/test/test.native.js | 8 ++++---- .../base/assert/is-probability/benchmark/benchmark.js | 10 ++++++---- .../is-probability/benchmark/benchmark.native.js | 10 ++++++---- .../assert/is-probabilityf/benchmark/benchmark.js | 6 ++---- .../is-probabilityf/benchmark/benchmark.native.js | 4 +--- 10 files changed, 51 insertions(+), 35 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.js index da1d291b5800..a3fa9c582653 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; var isPositiveZerof = require( './../lib' ); @@ -30,14 +30,19 @@ var isPositiveZerof = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { + var opts; var x; var y; var i; + opts = { + 'dtype': 'float32' + }; + x = uniform( 100, -50.0, 50.0, opts ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100.0 ) - 50.0; - y = isPositiveZerof( x ); + y = isPositiveZerof( x[ i%x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.native.js index b210a6c50271..6dfe6046e00c 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -39,14 +39,19 @@ var opts = { // MAIN // bench( pkg+'::native', opts, function benchmark( b ) { + var opts; var x; var y; var i; + opts = { + 'dtype': 'float32' + }; + x = uniform( 100, -50.0, 50.0, opts ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100.0 ) - 50.0; - y = isPositiveZerof( x ); + y = isPositiveZerof( x[ i%x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/benchmark.c index 1361a5bc4f88..bdcc0f7628f9 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/benchmark.c @@ -101,15 +101,18 @@ bool is_positive_zerof( float x ) { */ static double benchmark( void ) { double elapsed; + float x[ 100 ]; double t; - float x; bool y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 100.0f*rand_float() ) - 50.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 100.0f*rand_float() ) - 50.0f; - y = is_positive_zerof( x ); + y = is_positive_zerof( x[ i%100 ] ); if ( y != true && y != false ) { printf( "should return true or false\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/native/benchmark.c index 9c5206ef3448..d68e5e6ac637 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/native/benchmark.c @@ -92,15 +92,18 @@ static float rand_float( void ) { */ static double benchmark( void ) { double elapsed; + float x[ 100 ]; double t; - float x; bool b; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = (rand_float()*100.0f) - 50.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = (rand_float()*100.0f) - 50.0f; - b = stdlib_base_is_positive_zerof( x ); + b = stdlib_base_is_positive_zerof( x[ i%100 ] ); if ( b != true && b != false ) { printf( "should return either true or false\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.js b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.js index f55c7f635dcf..cde934301ef3 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.js @@ -33,13 +33,13 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function returns `true` if provided `+0`', function test( t ) { - t.equal( isPositiveZerof( 0.0 ), true, 'returns true' ); - t.equal( isPositiveZerof( +0.0 ), true, 'returns true' ); + t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' ); + t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `-0`', function test( t ) { - t.equal( isPositiveZerof( -0.0 ), false, 'returns false' ); + t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' ); t.end(); }); @@ -62,7 +62,7 @@ tape( 'the function returns `false` if not provided `+0`', function test( t ) { ]; for ( i = 0; i < values.length; i++ ) { - t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] ); + t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.native.js index 9e4aa20d2033..5e12ea05f2a6 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.native.js @@ -42,13 +42,13 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function returns `true` if provided `+0`', opts, function test( t ) { - t.equal( isPositiveZerof( 0.0 ), true, 'returns true' ); - t.equal( isPositiveZerof( +0.0 ), true, 'returns true' ); + t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' ); + t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `-0`', opts, function test( t ) { - t.equal( isPositiveZerof( -0.0 ), false, 'returns false' ); + t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' ); t.end(); }); @@ -71,7 +71,7 @@ tape( 'the function returns `false` if not provided `+0`', opts, function test( ]; for ( i = 0; i < values.length; i++ ) { - t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] ); + t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js index d8aa7b920c5f..2d374025af21 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js @@ -30,17 +30,19 @@ var isProbability = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var len; + var opts; var x; var y; var i; - len = 100; - x = uniform( len, 1.0, -1.0 ); + opts = { + 'dtype': 'float64' + }; + x = uniform( 100, -1.0, 1.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = isProbability( x[ i % len ] ); + y = isProbability( x[ i % x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js index f839abf3e90f..1c04deb0eb59 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js @@ -39,17 +39,19 @@ var opts = { // MAIN // bench( pkg+'::native', opts, function benchmark( b ) { - var len; + var opts; var x; var y; var i; - len = 100; - x = uniform( len, -1.0, 1.0 ); + opts = { + 'dtype': 'float64' + }; + x = uniform( 100, -1.0, 1.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = isProbability( x[ i % len ] ); + y = isProbability( x[ i % x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.js index 24c4d5306918..04942ba358f2 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.js @@ -31,20 +31,18 @@ var isProbabilityf = require( './../lib' ); bench( pkg, function benchmark( b ) { var opts; - var len; var x; var y; var i; - len = 100; opts = { 'dtype': 'float32' }; - x = uniform( len, -1.0, 1.0, opts ); + x = uniform( 100, -1.0, 1.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = isProbabilityf( x[ i % len ] ); + y = isProbabilityf( x[ i % x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js index 626c38263586..0a144470d2b9 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js @@ -40,12 +40,10 @@ var opts = { bench( pkg+'::native', opts, function benchmark( b ) { var opts; - var len; var x; var y; var i; - len = 100; opts = { 'dtype': 'float32' }; @@ -53,7 +51,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = isProbabilityf( x[ i % len ] ); + y = isProbabilityf( x[ i % x.length ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } From 112e55c19380a7e2a1fae4b45cc0e127aff1e939 Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Tue, 15 Apr 2025 15:10:45 +0530 Subject: [PATCH 2/2] update benchmark.native.js Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- .../base/assert/is-probabilityf/benchmark/benchmark.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js index 0a144470d2b9..7948c4c1d2c2 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js @@ -47,7 +47,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { opts = { 'dtype': 'float32' }; - x = uniform( len, -1.0, 1.0, opts ); + x = uniform( 100, -1.0, 1.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) {