Skip to content

Commit ae08a29

Browse files
bench: refactor random number generation in stats/base/dists/lognormal
PR-URL: #5164 Closes: #4979 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 4d79bde commit ae08a29

File tree

15 files changed

+315
-95
lines changed

15 files changed

+315
-95
lines changed

Diff for: lib/node_modules/@stdlib/stats/base/dists/lognormal/cdf/benchmark/benchmark.js

+21-7
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 uniform = require( '@stdlib/random/base/uniform' );
25+
var Float64Array = require( '@stdlib/array/float64' );
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 sigma;
36+
var len;
3537
var mu;
3638
var x;
3739
var y;
3840
var i;
3941

42+
len = 100;
43+
x = new Float64Array( len );
44+
mu = new Float64Array( len );
45+
sigma = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
x[ i ] = uniform( -100.0, 0.0 );
48+
mu[ i ] = uniform( -50.0, 50.0 );
49+
sigma[ i ] = uniform( EPS, 20.0 );
50+
}
51+
4052
b.tic();
4153
for ( i = 0; i < b.iterations; i++ ) {
42-
x = ( randu()*100.0 ) - 100;
43-
mu = ( randu()*100.0 ) - 50.0;
44-
sigma = ( randu()*20.0 ) + EPS;
45-
y = cdf( x, mu, sigma );
54+
y = cdf( x[ i % len ], mu[ i % len ], sigma[ 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 sigma;
70+
var len;
6171
var mu;
6272
var x;
6373
var y;
@@ -66,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) {
6676
mu = 10.0;
6777
sigma = 4.0;
6878
mycdf = cdf.factory( mu, sigma );
79+
len = 100;
80+
x = new Float64Array( len );
81+
for ( i = 0; i < len; i++ ) {
82+
x[ i ] = uniform( 0.0, 50.0 );
83+
}
6984

7085
b.tic();
7186
for ( i = 0; i < b.iterations; i++ ) {
72-
x = randu() * 50.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)