stdlib-js / stdlib-js/stdlib

[RFC]: Refactor random number generation in JS benchmarks for `stats/base/dists/signrank`

Ouverte
#4,986 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Benchmarks difficulty: 1 Good First Issue JavaScript RFC
Langage dominant
JavaScript
Étoiles
6k
Forks
1.3k
Merge moyen
1 j 3 h
PR mergées (30 j)
611

Description

### Description

This RFC proposes improving random number generation in JS benchmarks for [`stats/base/dists/signrank`](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/signrank).

**Context**: At present, in the remaining packages, random number generation in JS benchmarks occurs inside the benchmarking loop. Since random number generation is an expensive operation, it should be moved out of the benchmarking loops and initialized beforehand to avoid interfering with the results.

When adding support, the following tasks should be completed:

1. Move random number generation out of the benchmarking loops and initialize it before the benchmarks.

2. Ensure that the generated random values use the same range as the existing values to maintain consistency.

3. Use `uniform` and `discreteUniform` from `@stdlib/random/base/uniform` and `@stdlib/random/base/discrete-uniform` instead of `randu` expressions.
- For example, replace `( randu() * 10.0 + EPS )` with `uniform( EPS, 10.0 )`.
- Replace `ceil( randu() * 10.0 + EPS )` with `discreteUniform( 1, 10 )`.

To provide a concrete example of what a PR implementing the desired changes should contain, see #4837 and #4955, which provide examples for using both `uniform` and `discreteUniform`.

### Related Issues

#4837, #4955

### Questions

No.

### Other

Once the implementation is complete, you should be able to run the following `make` commands:

#### Build Native Add-on
```sh
NODE_ADDONS_PATTERN="@stdlib/stats/base/dists/signrank/*" make install-node-addons
```

#### Run JavaScript Benchmarks
```sh
make benchmark-javascript-files FILES="$(pwd)/lib/node_modules/@stdlib/stats/base/dists/signrank/*/benchmark/benchmark.js"
```

#### Run JavaScript Native Benchmarks
```sh
make benchmark-javascript-files FILES="$(pwd)/lib/node_modules/@stdlib/stats/base/dists/signrank/*/benchmark/benchmark.native.js"
```

**Note:** If running benchmarks results in an error, it is likely due to the random number generators producing values where the functions are not defined. To resolve this, check the relevant benchmark files, adjust the input value ranges to ensure they remain within the domain where the functions are valid, and then rerun the benchmarks. Reference: [#4955](https://github.com/stdlib-js/stdlib/pull/4955#issuecomment-2622578367)

### Checklist

- [x] I have read and understood the [Code of Conduct](https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md).
- [x] Searched for existing issues and pull requests.
- [x] The issue name begins with `RFC:`.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Inspect the benchmark/benchmark.js and benchmark.native.js files under lib/node_modules/@stdlib/stats/base/dists/signrank, and compare the patterns in #4837 and #4955. Move random-value generation before each benchmark, preserve the existing ranges, and use uniform or discreteUniform as appropriate. Build the native addon and run both benchmark commands listed in the issue to verify completion.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, nodejs
Domaine
performance
Type d'issue
Refactorisation
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.