Skip to content

Commit 41e3aaa

Browse files
committed
bench: move random number generation outside the benchmarking 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: 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 8409bd1 commit 41e3aaa

File tree

22 files changed

+288
-100
lines changed

22 files changed

+288
-100
lines changed

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

Lines changed: 19 additions & 6 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 pkg = require( './../package.json' ).name;
2728
var cdf = require( './../lib' );
@@ -30,16 +31,23 @@ var cdf = require( './../lib' );
3031
// MAIN //
3132

3233
bench( pkg, function benchmark( b ) {
34+
var len;
3335
var mu;
3436
var x;
3537
var y;
3638
var i;
3739

40+
len = 100;
41+
x = new Float64Array( len );
42+
mu = new Float64Array( len );
43+
for ( i = 0; i < len; i++ ) {
44+
x[ i ] = uniform( -100.0, 0.0 );
45+
mu[ i ] = uniform( -50.0, 50.0 );
46+
}
47+
3848
b.tic();
3949
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*100.0 ) - 100;
41-
mu = ( randu()*100.0 ) - 50.0;
42-
y = cdf( x, mu );
50+
y = cdf( x[ i % len ], mu[ i % len ] );
4351
if ( isnan( y ) ) {
4452
b.fail( 'should not return NaN' );
4553
}
@@ -54,18 +62,23 @@ bench( pkg, function benchmark( b ) {
5462

5563
bench( pkg+':factory', function benchmark( b ) {
5664
var mycdf;
65+
var len;
5766
var mu;
5867
var x;
5968
var y;
6069
var i;
6170

6271
mu = 40.0;
6372
mycdf = cdf.factory( mu );
73+
len = 100;
74+
x = new Float64Array( len );
75+
for ( i = 0; i < len; i++ ) {
76+
x[ i ] = uniform( 0.0, 100.0 );
77+
}
6478

6579
b.tic();
6680
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*100.0 );
68-
y = mycdf( x );
81+
y = mycdf( x[ i % len ] );
6982
if ( isnan( y ) ) {
7083
b.fail( 'should not return NaN' );
7184
}

0 commit comments

Comments
 (0)