Skip to content

Commit

Permalink
bench: refactor random number generation in stats/base/dists/cosine
Browse files Browse the repository at this point in the history
PR-URL: #4861
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
anandkaranubc authored Jan 26, 2025
1 parent 6d3a881 commit 247af42
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
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 @@ -44,9 +44,9 @@ bench( pkg, function benchmark( b ) {
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*100.0 ) - 50.0;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
x[ i ] = uniform( -50.0, 50.0 );
mu[ i ] = uniform( -10.0, 10.0 );
s[ i ] = uniform( EPS, 5.0 );
}

b.tic();
Expand All @@ -66,6 +66,7 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var mu;
var s;
var x;
Expand All @@ -75,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) {
mu = 10.0;
s = 4.0;
mycdf = cdf.factory( mu, s );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 50.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*50.0 );
y = mycdf( x );
y = mycdf( x[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var EPS = require( '@stdlib/constants/float64/eps' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
Expand Down Expand Up @@ -53,9 +53,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*100.0 ) - 50.0;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
x[ i ] = uniform( -50.0, 50.0 );
mu[ i ] = uniform( -10.0, 10.0 );
s[ i ] = uniform( EPS, 5.0 );
}

b.tic();
Expand Down
Loading

0 comments on commit 247af42

Please sign in to comment.