Skip to content

Commit 574d6e8

Browse files
committed
bench: refactor: Refactor random number generation in JS benchmarks for stats/base/dists/normal
--- 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 ---
1 parent 0258691 commit 574d6e8

File tree

17 files changed

+341
-108
lines changed

17 files changed

+341
-108
lines changed

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

Lines changed: 20 additions & 7 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 Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
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;
@@ -32,17 +33,24 @@ var cdf = require( './../lib' );
3233

3334
bench( pkg, function benchmark( b ) {
3435
var sigma;
36+
var len;
3537
var mu;
3638
var x;
3739
var y;
3840
var i;
3941

42+
len = 100;
43+
x = new Float64Array( len );
44+
mu = new Float64Array( len );
45+
sigma = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
x[ i ] = uniform( -100.0, 100.0 );
48+
mu[ i ] = uniform( -50.0, 50.0 );
49+
sigma[ i ] = uniform( EPS, 20.0 );
50+
}
4051
b.tic();
4152
for ( i = 0; i < b.iterations; i++ ) {
42-
x = ( randu()*200.0 ) - 100;
43-
mu = ( randu()*100.0 ) - 50.0;
44-
sigma = ( randu()*20.0 ) + EPS;
45-
y = cdf( x, mu, sigma );
53+
y = cdf( x[ i % len ], mu[ i % len ], sigma[ i % len ] );
4654
if ( isnan( y ) ) {
4755
b.fail( 'should not return NaN' );
4856
}
@@ -58,6 +66,7 @@ bench( pkg, function benchmark( b ) {
5866
bench( pkg+':factory', function benchmark( b ) {
5967
var mycdf;
6068
var sigma;
69+
var len;
6170
var mu;
6271
var x;
6372
var y;
@@ -66,11 +75,15 @@ bench( pkg+':factory', function benchmark( b ) {
6675
mu = 0.0;
6776
sigma = 1.5;
6877
mycdf = cdf.factory( mu, sigma );
78+
len = 100;
79+
x = new Float64Array( len );
80+
for ( i = 0; i < len; i++ ) {
81+
x[ i ] = uniform( -3.0, 3.0 );
82+
}
6983

7084
b.tic();
7185
for ( i = 0; i < b.iterations; i++ ) {
72-
x = ( randu()*6.0 ) - 3.0;
73-
y = mycdf( x );
86+
y = mycdf( x[ i % len ] );
7487
if ( isnan( y ) ) {
7588
b.fail( 'should not return NaN' );
7689
}

0 commit comments

Comments
 (0)