Skip to content

Commit 0ff98d9

Browse files
committed
fix: move random number generation outside benchmark loops
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 44141ab commit 0ff98d9

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

lib/node_modules/@stdlib/stats/base/dists/signrank/cdf/benchmark/benchmark.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ var cdf = require( './../lib' );
3131
// MAIN //
3232

3333
bench( pkg, function benchmark( b ) {
34-
var n;
34+
var nValues;
35+
var values;
3536
var x;
36-
var y;
3737
var i;
38+
var y;
39+
40+
values = new Array( b.iterations );
41+
nValues = new Array( b.iterations );
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
values[ i ] = uniform( 0.0, 20.0 );
44+
nValues[ i ] = discreteUniform( 1, 20 );
45+
}
3846

3947
b.tic();
4048
for ( i = 0; i < b.iterations; i++ ) {
41-
x = uniform( 0.0, 20.0 );
42-
n = discreteUniform( 1, 20 );
43-
y = cdf( x, n );
49+
x = values[ i ];
50+
y = cdf( x, nValues[ i ] );
4451
if ( isnan( y ) ) {
4552
b.fail( 'should not return NaN' );
4653
}
@@ -54,6 +61,7 @@ bench( pkg, function benchmark( b ) {
5461
});
5562

5663
bench( pkg+':factory', function benchmark( b ) {
64+
var values;
5765
var mycdf;
5866
var n;
5967
var x;
@@ -63,9 +71,14 @@ bench( pkg+':factory', function benchmark( b ) {
6371
n = 20;
6472
mycdf = cdf.factory( n );
6573

74+
values = new Array( b.iterations );
75+
for ( i = 0; i < b.iterations; i++ ) {
76+
values[ i ] = uniform( 0.0, 20.0 );
77+
}
78+
6679
b.tic();
6780
for ( i = 0; i < b.iterations; i++ ) {
68-
x = uniform( 0.0, 20.0 );
81+
x = values[ i ];
6982
y = mycdf( x );
7083
if ( isnan( y ) ) {
7184
b.fail( 'should not return NaN' );

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/benchmark/benchmark.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,21 @@ var pdf = require( './../lib' );
3131
// MAIN //
3232

3333
bench( pkg, function benchmark( b ) {
34-
var n;
35-
var x;
34+
var nValues;
35+
var values;
3636
var y;
3737
var i;
3838

39+
values = new Array( b.iterations );
40+
nValues = new Array( b.iterations );
41+
for ( i = 0; i < b.iterations; i++ ) {
42+
values[ i ] = uniform( 0.0, 10.0 );
43+
nValues[ i ] = discreteUniform( 1, 20 );
44+
}
45+
3946
b.tic();
4047
for ( i = 0; i < b.iterations; i++ ) {
41-
x = uniform(0.0, 10.0);
42-
n = discreteUniform( 1, 20 );
43-
y = pdf( x, n );
48+
y = pdf( values[ i ], nValues[ i ] );
4449
if ( isnan( y ) ) {
4550
b.fail( 'should not return NaN' );
4651
}
@@ -54,19 +59,22 @@ bench( pkg, function benchmark( b ) {
5459
});
5560

5661
bench( pkg+':factory', function benchmark( b ) {
62+
var values;
5763
var mypdf;
5864
var n;
59-
var x;
6065
var y;
6166
var i;
6267

68+
values = new Array( b.iterations );
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
values[ i ] = uniform( 0.0, 20.0 );
71+
}
6372
n = 20;
6473
mypdf = pdf.factory( n );
6574

6675
b.tic();
6776
for ( i = 0; i < b.iterations; i++ ) {
68-
x = uniform(0.0, 20.0);
69-
y = mypdf( x );
77+
y = mypdf( values[ i ] );
7078
if ( isnan( y ) ) {
7179
b.fail( 'should not return NaN' );
7280
}

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/benchmark/benchmark.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' );
25-
var randint = require( '@stdlib/random/base/discrete-uniform' );
2624
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2727
var pkg = require( './../package.json' ).name;
2828
var quantile = require( './../lib' );
29+
var EPS = 1e-10;
2930

3031

3132
// MAIN //
@@ -38,8 +39,8 @@ bench( pkg, function benchmark( b ) {
3839

3940
b.tic();
4041
for ( i = 0; i < b.iterations; i++ ) {
41-
p = uniform( 0.0, 1.0 );
42-
n = randint( 1, 200 );
42+
p = uniform( EPS, 1.0 );
43+
n = discreteUniform( 1, 200 );
4344
y = quantile( p, n );
4445
if ( isnan( y ) ) {
4546
b.fail( 'should not return NaN' );
@@ -65,7 +66,7 @@ bench( pkg+':factory', function benchmark( b ) {
6566

6667
b.tic();
6768
for ( i = 0; i < b.iterations; i++ ) {
68-
p = uniform( 0.0, 1.0 );
69+
p = uniform( EPS, 1.0 );
6970
y = myquantile( p );
7071
if ( isnan( y ) ) {
7172
b.fail( 'should not return NaN' );

0 commit comments

Comments
 (0)