Skip to content

bench: update random value generation #7748

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

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

AryanJ18
Copy link
Contributor

@AryanJ18 AryanJ18 commented Jul 26, 2025

Resolves #4989

Description

What is the purpose of this pull request?

This pull request:

  • It initialized the random number generation out of the benchmarking loops .
  • Replaced the use of randu with uniform

Related Issues

Does this pull request have any related issues?

  • NO

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

In the issue it is mentioned to use uniform and discreteUniform to replace randu but I did not find any case in which discreteUniform could be used as per my knowledge

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. Good First PR A pull request resolving a Good First Issue. labels Jul 26, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jul 26, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/triangular/ctor $\color{green}524/524$
$\color{green}+100.00\%$
$\color{green}58/58$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}524/524$
$\color{green}+100.00\%$
stats/base/dists/triangular/entropy $\color{green}206/206$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}206/206$
$\color{green}+100.00\%$
stats/base/dists/triangular/kurtosis $\color{green}205/205$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}205/205$
$\color{green}+100.00\%$
stats/base/dists/triangular/mean $\color{green}189/189$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}189/189$
$\color{green}+100.00\%$
stats/base/dists/triangular/median $\color{green}197/197$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}197/197$
$\color{green}+100.00\%$
stats/base/dists/triangular/mode $\color{green}189/189$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}189/189$
$\color{green}+100.00\%$
stats/base/dists/triangular/pdf $\color{green}348/348$
$\color{green}+100.00\%$
$\color{green}39/39$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}348/348$
$\color{green}+100.00\%$
stats/base/dists/triangular/skewness $\color{green}210/210$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}210/210$
$\color{green}+100.00\%$
stats/base/dists/triangular/stdev $\color{green}206/206$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}206/206$
$\color{green}+100.00\%$
stats/base/dists/triangular/variance $\color{green}197/197$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}197/197$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@AryanJ18 AryanJ18 changed the title #4989 :Refactor random number generation in JS benchmarks for stats/base/dis… Resolves #4989 Jul 26, 2025
@AryanJ18 AryanJ18 changed the title Resolves #4989 bench: Moves random number generation out of benchmarking loop and replaces randu with uniform #4989 Jul 26, 2025
AryanJ18 added 4 commits July 27, 2025 01:41
chore: fix lint issues and reorder requires

bench: fixes a issue in random number generation
@AryanJ18 AryanJ18 changed the title bench: Moves random number generation out of benchmarking loop and replaces randu with uniform #4989 bench: moves random number generation out of benchmarking loop and replaces randu with uniform #4989 Jul 26, 2025
@AryanJ18
Copy link
Contributor Author

Hi @anandkaranubc, I’ve made sure all benchmarks pass locally and I’ve addressed all the lint errors that showed up so far (spacing, import order, header formatting, etc.).
However, I keep running into new lint issues one after another, even after I think I’ve fixed everything. Is there a better workflow or tool I can use to catch all lint errors before pushing or opening a PR?
Also, let me know if I should squash these commits or leave them as is.

@kgryte
Copy link
Member

kgryte commented Jul 27, 2025

@AryanJ18 Thank you for your PR. However, your proposed changes contain significant deviations from our style conventions. I suppose going back through and comparing to other packages to ensure that everything looks and feels like other packages (e.g., in terms of spacing, etc.).

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jul 27, 2025
@anandkaranubc anandkaranubc self-requested a review July 28, 2025 18:25
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 28, 2025
Comment on lines +36 to +37
var as = new Float64Array(bm.iterations);
var bs = new Float64Array(bm.iterations);
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 be changed to follow what is done in https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/stats/base/dists/arcsine/ctor/benchmark/benchmark.js

Like:

	var dist;
    var len;
	var a;
	var b;
	var c;
	var i;

    len = 100;
	a = new Float64Array( len );
	b = new Float64Array( len );
	c = new Float64Array( len );
    for ( i = 0; i < len; i++ ) {
		a[ i ] = uniform( EPS, 10.0 );
		b[ i ] = uniform( a[ i ] + EPS, a[ i ] + 10.0 + EPS );
        c[ i ] = uniform( a[ i ], b[ i ] );
	}

c = ( randu() * ( b-a ) ) + a;
a = as[i];
b = bs[i];
c = cs[i];
dist = new Triangular( a, b, c );
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
dist = new Triangular( a, b, c );
dist = new Triangular( a[ i%len ], b[ i%len ], c[ i%len ] );

After the above changes have been made.

@anandkaranubc anandkaranubc removed the Needs Review A pull request which needs code review. label Jul 28, 2025
@@ -98,7 +110,7 @@ bench( pkg+'::set:a', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
y = ( 100.0*randu() ) + EPS;
y = uniform(EPS, 100.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be moved outside the benchmarking loop, similar to what's being done above.

max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
min[ i ] = uniform( 0.0, 10.0 );
max[ i ] = uniform( min[ i ] + EPS, 10.0 + min[ i ] + EPS );
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
max[ i ] = uniform( min[ i ] + EPS, 10.0 + min[ i ] + EPS );
max[ i ] = uniform( min[ i ] + EPS, min[ i ] + 10.0 + EPS );

Just to be consistent with the other benchmarks. This change applies throughout the PR.

max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
min[ i ] = uniform( 0.0, 10.0 );
max[ i ] = uniform( min[ i ] + EPS, 10.0 + min[ i ] + EPS );
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. Rest looks good :)

@anandkaranubc anandkaranubc changed the title bench: moves random number generation out of benchmarking loop and replaces randu with uniform #4989 bench: update random value generation Jul 28, 2025
@anandkaranubc anandkaranubc added the Benchmarks Pull requests adding or improving benchmarks for measuring performance. label Jul 28, 2025
@anandkaranubc
Copy link
Contributor

@AryanJ18 The PR looks in good shape overall. Thank you for making the changes as Athan suggested. Just a few changes remain, as mentioned above.

@AryanJ18
Copy link
Contributor Author

Thank you! I’ll make the remaining changes as suggested and push the update shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Benchmarks Pull requests adding or improving benchmarks for measuring performance. Good First PR A pull request resolving a Good First Issue. Needs Changes Pull request which needs changes before being merged. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Refactor random number generation in JS benchmarks for stats/base/dists/triangular
4 participants