Skip to content

bench: refactor random number generation in JS benchmarks for stats/base/dists/uniform #5176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 12, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );
Expand All @@ -32,16 +33,24 @@
bench( pkg, function benchmark( b ) {
var min;
var max;
var len;
var x;
var y;
var i;

len = 100;
x = new Float64Array( len );
min = new Float64Array( len );
max = new Float64Array( len );
for( i = 0; i < len; i++ ){

Check failure on line 45 in lib/node_modules/@stdlib/stats/base/dists/uniform/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected space(s) after "for"

Check failure on line 45 in lib/node_modules/@stdlib/stats/base/dists/uniform/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Missing space before opening brace
x[ i ] = uniform( -10.0, 10.0 );
min[ i ] = uniform( -20.0, 0.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 40.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 20.0 ) - 10.0;
min = ( randu() * 20.0 ) - 20.0;
max = min + ( randu() * 40.0 );
y = cdf( x, min, max );
y = cdf( x[ i % len ], min[ i % len ], max[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,18 +67,23 @@
var mycdf;
var min;
var max;
var len;
var x;
var y;
var i;

min = -1.5;
max = 1.5;
mycdf = cdf.factory( min, max );
len = 100;
x = new Float64Array( len );
for( i = 0; i < len; i++ ){

Check failure on line 80 in lib/node_modules/@stdlib/stats/base/dists/uniform/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected space(s) after "for"

Check failure on line 80 in lib/node_modules/@stdlib/stats/base/dists/uniform/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Missing space before opening brace
x[ i ] = uniform( -2.0, 0.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*2.0 ) - 2.0;
y = mycdf( x );
y = mycdf( x[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Loading
Loading