Skip to content
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 Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
Expand All @@ -32,17 +33,25 @@ var cdf = require( './../lib' );

bench( pkg, function benchmark( b ) {
var scale;
var len;
var mu;
var x;
var y;
var i;

len = 100;
mu = new Float64Array( len );
scale = new Float64Array( len );
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
mu[ i ] = uniform( -50.0, 50.0 );
x[ i ] = uniform( mu[ i ], 50.0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x[ i ] = uniform( mu[ i ], 50.0 );
x[ i ] = uniform( mu[ i ], 100.0 );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range should remain the same as original. This also applies throughout the PR.

scale[ i ] = uniform( EPS, 20.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
mu = ( randu()*100.0 ) - 50.0;
x = ( randu()*100.0 ) + mu;
scale = ( randu()*20.0 ) + EPS;
y = cdf( x, mu, scale );
y = cdf( x[ i % len ], mu[ i % len ], scale[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,19 +67,24 @@ bench( pkg, function benchmark( b ) {
bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var scale;
var len;
var mu;
var x;
var y;
var i;

mu = 0.0;
scale = 1.5;
len = 100;
x = new Float64Array( len );
mycdf = cdf.factory( mu, scale );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( -4.0, 4.0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x[ i ] = uniform( -4.0, 4.0 );
x[ i ] = uniform( 0.0, 4.0 );

Same comment as above.

}

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