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 1 commit
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,10 +21,10 @@
// 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 //
Expand All @@ -36,12 +36,13 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

q = uniform( 0.0, 12.0 );
r = uniform( 2.0, 20.0 );
v = 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.

Here, q, r, and v should each be a Float64Array of length 100 and should be initialized in a loop. Reference PRs will help.

y = cdf( q, r, v );
Copy link
Contributor

Choose a reason for hiding this comment

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

This should still remain in the benchmarking loop, as it is the part being benchmarked.


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 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -65,11 +66,11 @@ bench( pkg+':factory', function benchmark( b ) {
v = 5.0;
r = 3.0;
mycdf = cdf.factory( v, r );
q = uniform( 0.0, 1.0 );
y = mycdf( q );
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.

std
Is this the right approach ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, considering you are using the correct range for random number generation.


b.tic();
for ( i = 0; i < b.iterations; i++ ) {
q = randu();
y = mycdf( q );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
// 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 //
Expand All @@ -36,12 +36,13 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

p = uniform( 0.0, 1.0 );
r = uniform( 2.0, 20.0 );
v = uniform( 2.0, 20.0 );
y = quantile( p, r, v );

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 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -65,11 +66,11 @@ bench( pkg+':factory', function benchmark( b ) {
v = 5.0;
r = 3.0;
myquantile = quantile.factory( v, r );
p = uniform( 0.0, 1.0 );
y = myquantile( p );

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