Skip to content

Commit 29ee535

Browse files
committed
bench: refactor random number generation in stats/base/dists/t
--- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent e924862 commit 29ee535

File tree

8 files changed

+202
-53
lines changed

8 files changed

+202
-53
lines changed

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var ceil = require( '@stdlib/math/base/special/ceil' );
25-
var randu = require( '@stdlib/random/base/randu' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var pkg = require( './../package.json' ).name;
2829
var cdf = require( './../lib' );
@@ -31,16 +32,23 @@ var cdf = require( './../lib' );
3132
// MAIN //
3233

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

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

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

72+
len = 100;
73+
x = new Float64Array( len );
74+
for ( i = 0; i < len; i++ ) {
75+
x[ i ] = uniform( -50.0, 50.0 );
76+
}
77+
6378
v = 3.0;
6479
mycdf = cdf.factory( v );
6580

6681
b.tic();
6782
for ( i = 0; i < b.iterations; i++ ) {
68-
x = ( randu()*100.0 ) - 50.0;
69-
y = mycdf( x );
83+
y = mycdf( x[ i % len ] );
7084
if ( isnan( y ) ) {
7185
b.fail( 'should not return NaN' );
7286
}

0 commit comments

Comments
 (0)