Skip to content

bench: refactor random number generation in stats/base/dists/studentized-range #5175

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

Merged
merged 13 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -21,27 +21,35 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );
var uniform = require('@stdlib/random/base/uniform')


// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var v;
var r;
var q;
var y;
var i;

len = 100;
q = new Float64Array( len );
r = new Float64Array( len );
v = new Float64Array( len );
for( i = 0; i < len; i++ ) {
q[i] = uniform( 0.0, 12.0 );
r[i] = uniform( 2.0, 20.0 );
v[i] = uniform( 2.0, 20.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
q = randu() * 12.0;
r = ( randu()*20.0 ) + 2.0;
v = ( randu()*20.0 ) + 2.0;
y = cdf( q, r, v );
y = cdf( q[ i % len ], r[ i % len ], v[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -56,20 +64,25 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var r;
var q;
var v;
var y;
var i;

len = 100;
v = 5.0;
r = 3.0;
q = new Float64Array( len );
mycdf = cdf.factory( v, r );
for ( i = 0; i < len; i++ ) {
q[i] = uniform( 0.0, 1.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
q = randu();
y = mycdf( q );
y = mycdf( q[ 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 @@ -21,27 +21,36 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var quantile = require( './../lib' );
const uniform = require('@stdlib/random/base/uniform');


// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var v;
var r;
var p;
var y;
var i;


len = 100;
p = new Float64Array( len );
r = new Float64Array( len );
v = new Float64Array( len );
for( i = 0; i < len; i++ ) {
p[i] = uniform( 0.0, 1.0 );
r[i] = uniform( 2.0, 20.0 );
v[i] = uniform( 2.0, 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.

Same comment as above, and applies throughout the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
p = randu();
r = ( randu()*20.0 ) + 2.0;
v = ( randu()*20.0 ) + 2.0;
y = quantile( p, r, v );
y = quantile( p[ i % len ], r[ i % len ], v[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -56,20 +65,25 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var myquantile;
var len;
var r;
var p;
var v;
var y;
var i;

len = 100;
v = 5.0;
r = 3.0;
p = new Float64Array( len );
myquantile = quantile.factory( v, r );
for ( i = 0; i < len; i++ ) {
p[i] = uniform( 0.0, 1.0 );
}

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