Skip to content

Commit 951d90c

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 611fed3 commit 951d90c

File tree

19 files changed

+301
-98
lines changed

19 files changed

+301
-98
lines changed

lib/node_modules/@stdlib/stats/base/dists/geometric/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 EPS = require( '@stdlib/constants/float64/eps' );
2728
var pkg = require( './../package.json' ).name;
@@ -31,16 +32,23 @@ var cdf = require( './../lib' );
3132
// MAIN //
3233

3334
bench( pkg, function benchmark( b ) {
35+
var len;
3436
var p;
3537
var x;
3638
var y;
3739
var i;
3840

41+
len = 100;
42+
x = new Float64Array( len );
43+
p = new Float64Array( len );
44+
for ( i = 0; i < len; i++ ) {
45+
x[ i ] = uniform( 0.0, 40.0 );
46+
p[ i ] = uniform( EPS, 1.0 );
47+
}
48+
3949
b.tic();
4050
for ( i = 0; i < b.iterations; i++ ) {
41-
x = randu()*40.0;
42-
p = ( randu()*1.0 ) + EPS;
43-
y = cdf( x, p );
51+
y = cdf( x[ i % len ], p[ i % len ] );
4452
if ( isnan( y ) ) {
4553
b.fail( 'should not return NaN' );
4654
}
@@ -55,18 +63,23 @@ bench( pkg, function benchmark( b ) {
5563

5664
bench( pkg+':factory', function benchmark( b ) {
5765
var mycdf;
66+
var len;
5867
var p;
5968
var x;
6069
var y;
6170
var i;
6271

6372
p = 0.3;
6473
mycdf = cdf.factory( p );
74+
len = 100;
75+
x = new Float64Array( len );
76+
for ( i = 0; i < len; i++ ) {
77+
x[ i ] = uniform( 0.0, 40.0 );
78+
}
6579

6680
b.tic();
6781
for ( i = 0; i < b.iterations; i++ ) {
68-
x = randu()*40.0;
69-
y = mycdf( x );
82+
y = mycdf( x[ i % len ] );
7083
if ( isnan( y ) ) {
7184
b.fail( 'should not return NaN' );
7285
}

0 commit comments

Comments
 (0)