Skip to content

Commit 9201902

Browse files
authored
Update benchmark.js
Signed-off-by: NANDANI SINGH <[email protected]>
1 parent e1cc668 commit 9201902

File tree

1 file changed

+28
-15
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/signrank/cdf/benchmark

1 file changed

+28
-15
lines changed

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,39 @@
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' );
2525
var ceil = require( '@stdlib/math/base/special/ceil' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
2828
var cdf = require( './../lib' );
2929

3030

3131
// MAIN //
32+
function generateRandomValues(iterations, minX, maxX, minN, maxN) {
33+
return {
34+
xValues: Array.from({ length: iterations }, () => uniform(minX, maxX)),
35+
nValues: Array.from({ length: iterations }, () => Math.ceil(uniform(minN, maxN)))
36+
};
37+
}
38+
3239

3340
bench( pkg, function benchmark( b ) {
41+
var { xValues, nValues } = generateRandomValues(b.iterations, 0, 20.0, 1, 20.0);
3442
var n;
3543
var x;
3644
var y;
3745
var i;
3846

3947
b.tic();
40-
for ( i = 0; i < b.iterations; i++ ) {
41-
x = randu() * 20.0;
42-
n = ceil( randu()*20.0 );
43-
y = cdf( x, n );
44-
if ( isnan( y ) ) {
45-
b.fail( 'should not return NaN' );
46-
}
47-
}
48+
for ( i = 0; i < b.iterations; i++) {
49+
x = xValues[i];
50+
n = nValues[i];
51+
y = cdf(x, n);
52+
if (isnan(y)) {
53+
b.fail('should not return NaN');
54+
}
55+
}
56+
4857
b.toc();
4958
if ( isnan( y ) ) {
5059
b.fail( 'should not return NaN' );
@@ -62,14 +71,18 @@ bench( pkg+':factory', function benchmark( b ) {
6271

6372
n = 20;
6473
mycdf = cdf.factory( n );
74+
const { xValues } = generateRandomValues(b.iterations, 0, 20.0);
6575

6676
b.tic();
67-
for ( i = 0; i < b.iterations; i++ ) {
68-
x = randu() * 20.0;
69-
y = mycdf( x );
70-
if ( isnan( y ) ) {
71-
b.fail( 'should not return NaN' );
72-
}
77+
78+
for ( i = 0; i < b.iterations; i++) {
79+
x = xValues[i];
80+
y = mycdf(x);
81+
if (isnan(y)) {
82+
b.fail('should not return NaN');
83+
}
84+
}
85+
7386
}
7487
b.toc();
7588
if ( isnan( y ) ) {

0 commit comments

Comments
 (0)