Skip to content

bench: refactor random number generation in stats/base/dists/triangular #5211

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
@@ -34,17 +35,26 @@ bench( pkg, function benchmark( b ) {
var mode;
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 );
mode = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 30.0 );
min[ i ] = uniform( 0.0, 10.0 );
max[ i ] = uniform( min[ i ] + EPS, min[ i ] + 40.0 );
mode[ i ] = uniform( min[ i ], max[ i ] );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 30.0;
min = randu() * 10.0;
max = min + ( randu() * 40.0 ) + EPS;
mode = min + ( ( max - min ) * randu() );
y = cdf( x, min, max, mode );
y = cdf( x[ i%len ], min[ i%len ], max[ i%len ], mode[ i%len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
@@ -62,6 +72,7 @@ bench( pkg+':factory', function benchmark( b ) {
var mode;
var min;
var max;
var len;
var x;
var y;
var i;
@@ -70,11 +81,15 @@ bench( pkg+':factory', function benchmark( b ) {
max = 1.5;
mode = 0.5;
mycdf = cdf.factory( min, max, mode );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
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' );
}

Large diffs are not rendered by default.