Skip to content

Commit ae5c2bb

Browse files
committed
bench(stats/base/dists/triangular): refactor random number generation in JS benchmarks
--- 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: na - 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 dbe9565 commit ae5c2bb

File tree

26 files changed

+311
-156
lines changed

26 files changed

+311
-156
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var Float64Array = require( '@stdlib/array/float64' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var EPS = require( '@stdlib/constants/float64/eps' );
2728
var pkg = require( './../package.json' ).name;
@@ -34,17 +35,26 @@ bench( pkg, function benchmark( b ) {
3435
var mode;
3536
var min;
3637
var max;
38+
var len;
3739
var x;
3840
var y;
3941
var i;
4042

43+
len = 100;
44+
x = new Float64Array( len );
45+
min = new Float64Array( len );
46+
max = new Float64Array( len );
47+
mode = new Float64Array( len );
48+
for ( i = 0; i < len; i++ ) {
49+
x[ i ] = uniform( 0.0, 30.0 );
50+
min[ i ] = uniform( 0.0, 10.0 );
51+
max[ i ] = uniform( min[ i ] + EPS, min[ i ] + 40.0 );
52+
mode[ i ] = uniform( min[ i ], max[ i ] );
53+
}
54+
4155
b.tic();
4256
for ( i = 0; i < b.iterations; i++ ) {
43-
x = randu() * 30.0;
44-
min = randu() * 10.0;
45-
max = min + ( randu() * 40.0 ) + EPS;
46-
mode = min + ( ( max - min ) * randu() );
47-
y = cdf( x, min, max, mode );
57+
y = cdf( x[ i%len ], min[ i%len ], max[ i%len ], mode[ i%len ] );
4858
if ( isnan( y ) ) {
4959
b.fail( 'should not return NaN' );
5060
}
@@ -62,6 +72,7 @@ bench( pkg+':factory', function benchmark( b ) {
6272
var mode;
6373
var min;
6474
var max;
75+
var len;
6576
var x;
6677
var y;
6778
var i;
@@ -70,11 +81,15 @@ bench( pkg+':factory', function benchmark( b ) {
7081
max = 1.5;
7182
mode = 0.5;
7283
mycdf = cdf.factory( min, max, mode );
84+
len = 100;
85+
x = new Float64Array( len );
86+
for ( i = 0; i < len; i++ ) {
87+
x[ i ] = uniform( -2.0, 0.0 );
88+
}
7389

7490
b.tic();
7591
for ( i = 0; i < b.iterations; i++ ) {
76-
x = ( randu()*2.0 ) - 2.0;
77-
y = mycdf( x );
92+
y = mycdf( x[ i % len ] );
7893
if ( isnan( y ) ) {
7994
b.fail( 'should not return NaN' );
8095
}

0 commit comments

Comments
 (0)