Skip to content

Commit 2b283ac

Browse files
bench: refactor random number generation in JS benchmarks for stats/base/dists/levy
--- 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 b78e8ba commit 2b283ac

File tree

1 file changed

+21
-7
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/levy/cdf/benchmark

1 file changed

+21
-7
lines changed

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

Lines changed: 21 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,25 @@ var cdf = require( './../lib' );
3233

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

42+
len = 100;
43+
mu = new Float64Array( len );
44+
scale = new Float64Array( len );
45+
x = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
mu[ i ] = uniform( -50.0, 100.0 );
48+
x[ i ] = uniform( mu[i], 100.0 );
49+
scale[ i ] = uniform( EPS, 20.0 );
50+
}
51+
4052
b.tic();
4153
for ( i = 0; i < b.iterations; i++ ) {
42-
mu = ( randu()*100.0 ) - 50.0;
43-
x = ( randu()*100.0 ) + mu;
44-
scale = ( randu()*20.0 ) + EPS;
45-
y = cdf( x, mu, scale );
54+
y = cdf( x[ i % len ], mu[ i% len], scale[ i % len] );
4655
if ( isnan( y ) ) {
4756
b.fail( 'should not return NaN' );
4857
}
@@ -58,6 +67,7 @@ bench( pkg, function benchmark( b ) {
5867
bench( pkg+':factory', function benchmark( b ) {
5968
var mycdf;
6069
var scale;
70+
var len;
6171
var mu;
6272
var x;
6373
var y;
@@ -66,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) {
6676
mu = 0.0;
6777
scale = 1.5;
6878
mycdf = cdf.factory( mu, scale );
79+
len=100;
80+
x = new Float64Array( len );
81+
for ( i = 0; i < len; i++ ) {
82+
x[ i ] = uniform( 0, 4.0 );
83+
}
6984

7085
b.tic();
7186
for ( i = 0; i < b.iterations; i++ ) {
72-
x = randu() * 4.0;
73-
y = mycdf( x );
87+
y = mycdf( x[ i % len ] );
7488
if ( isnan( y ) ) {
7589
b.fail( 'should not return NaN' );
7690
}

0 commit comments

Comments
 (0)