Skip to content

Commit 631d46c

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: passed - 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 c155b43 commit 631d46c

File tree

1 file changed

+18
-6
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark

1 file changed

+18
-6
lines changed

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var Float64Array = require( '@stdlib/array/float64' );
2525
var uniform = require( '@stdlib/random/base/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
@@ -31,16 +31,23 @@ var mgf = require( './../lib' );
3131
// MAIN //
3232

3333
bench( pkg, function benchmark( b ) {
34+
var len;
3435
var mu;
3536
var t;
3637
var y;
3738
var i;
3839

40+
len = 100;
41+
t = new Float64Array( len );
42+
mu = new Float64Array( len );
43+
for ( i = 0; i < len; i++ ) {
44+
t[ i ] = uniform( -100.0, 0.0 );
45+
mu[ i ] = uniform( -50.0, 50.0 );
46+
}
47+
3948
b.tic();
4049
for ( i = 0; i < b.iterations; i++ ) {
41-
t = uniform( -100.0, 0.0 );
42-
mu = uniform( -50.0, 50.0 );
43-
y = mgf( t, mu );
50+
y = mgf( t[ i % len ], mu[ i % len ] );
4451
if ( isnan( y ) ) {
4552
b.fail( 'should not return NaN' );
4653
}
@@ -55,18 +62,23 @@ bench( pkg, function benchmark( b ) {
5562

5663
bench( pkg+':factory', function benchmark( b ) {
5764
var mymgf;
65+
var len;
5866
var mu;
5967
var t;
6068
var y;
6169
var i;
6270

6371
mu = 40.0;
6472
mymgf = mgf.factory( mu );
73+
len = 100;
74+
t = new Float64Array( len );
75+
for ( i = 0; i < len; i++ ) {
76+
t[ i ] = uniform( 0.0, 100.0 );
77+
}
6578

6679
b.tic();
6780
for ( i = 0; i < b.iterations; i++ ) {
68-
t = randu() * 100.0;
69-
y = mymgf( t );
81+
y = mymgf( t[ i % len ] );
7082
if ( isnan( y ) ) {
7183
b.fail( 'should not return NaN' );
7284
}

0 commit comments

Comments
 (0)