Skip to content

Commit

Permalink
bench: refactor random number generation in `stats/base/dists/degener…
Browse files Browse the repository at this point in the history
…ate`

PR-URL: #4862
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
anandkaranubc authored Jan 26, 2025
1 parent ec68467 commit 1fc3918
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 100 deletions.
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 pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );
Expand All @@ -30,16 +31,23 @@ var cdf = require( './../lib' );
// MAIN //

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

len = 100;
x = new Float64Array( len );
mu = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( -100.0, 0.0 );
mu[ i ] = uniform( -50.0, 50.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 100;
mu = ( randu()*100.0 ) - 50.0;
y = cdf( x, mu );
y = cdf( x[ i % len ], mu[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -54,18 +62,23 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var mu;
var x;
var y;
var i;

mu = 40.0;
mycdf = cdf.factory( mu );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 100.0 );
}

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

0 comments on commit 1fc3918

Please sign in to comment.