Skip to content
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
Expand Up @@ -31,22 +31,19 @@ var cdf = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var alpha;
var beta;
var alpha = uniform( EPS, 100.0 );
var beta = uniform( EPS, 100.0 );
Comment on lines +34 to +35
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
var alpha = uniform( EPS, 100.0 );
var beta = uniform( EPS, 100.0 );
var alpha;
var beta;

Variable declarations happen at the top and separately from their initializations.

var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) + EPS;
alpha = ( randu()*100.0 ) + EPS;
beta = ( randu()*100.0 ) + EPS;
y = cdf( x, alpha, beta );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
for ( i = 0; i < b.iterations; i++ ) {
x = uniform( EPS, 20.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 use of uniform should be moved out of the benchmarking loop so it doesn't interfere with the benchmark results.

y = cdf( x, alpha, beta );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand All @@ -56,25 +53,21 @@ bench( pkg, function benchmark( b ) {
});

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var alpha;
var beta;
var alpha = 100.56789;
var beta = 55.54321;
var mycdf = cdf.factory( alpha, beta );
Comment on lines +57 to +58
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

var x;
var y;
var i;

alpha = 100.56789;
beta = 55.54321;
mycdf = cdf.factory( alpha, beta );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*50.0 ) + EPS;
y = mycdf( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
x = uniform( EPS, 50.0 );
y = mycdf( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Loading