Skip to content

Commit 5e9a7cd

Browse files
authored
bench: update random value generation
PR-URL: #9738 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent a6b5609 commit 5e9a7cd

File tree

1 file changed

+106
-24
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/ctor/benchmark

1 file changed

+106
-24
lines changed

lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/ctor/benchmark/benchmark.js

Lines changed: 106 additions & 24 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 uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var EPS = require( '@stdlib/constants/float64/eps' );
2727
var pkg = require( './../package.json' ).name;
@@ -32,15 +32,20 @@ var Kumaraswamy = require( './../lib' );
3232

3333
bench( pkg+'::instantiation', function benchmark( bm ) {
3434
var dist;
35+
var opts;
3536
var a;
3637
var b;
3738
var i;
3839

40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
a = uniform( 100, EPS, 10.0, opts );
44+
b = uniform( 100, EPS, 10.0, opts );
45+
3946
bm.tic();
4047
for ( i = 0; i < bm.iterations; i++ ) {
41-
a = ( randu() * 10.0 ) + EPS;
42-
b = ( randu() * 10.0 ) + EPS;
43-
dist = new Kumaraswamy( a, b );
48+
dist = new Kumaraswamy( a[ i % a.length ], b[ i % b.length ] );
4449
if ( !( dist instanceof Kumaraswamy ) ) {
4550
bm.fail( 'should return a distribution instance' );
4651
}
@@ -81,6 +86,7 @@ bench( pkg+'::get:a', function benchmark( bm ) {
8186

8287
bench( pkg+'::set:a', function benchmark( bm ) {
8388
var dist;
89+
var opts;
8490
var a;
8591
var b;
8692
var y;
@@ -90,10 +96,14 @@ bench( pkg+'::set:a', function benchmark( bm ) {
9096
b = 55.54321;
9197
dist = new Kumaraswamy( a, b );
9298

99+
opts = {
100+
'dtype': 'float64'
101+
};
102+
y = uniform( 100, EPS, 100.0, opts );
103+
93104
bm.tic();
94105
for ( i = 0; i < bm.iterations; i++ ) {
95-
y = ( 100.0*randu() ) + EPS;
96-
dist.a = y;
106+
dist.a = y[ i % y.length ];
97107
if ( dist.a !== y ) {
98108
bm.fail( 'should return set value' );
99109
}
@@ -134,6 +144,7 @@ bench( pkg+'::get:b', function benchmark( bm ) {
134144

135145
bench( pkg+'::set:b', function benchmark( bm ) {
136146
var dist;
147+
var opts;
137148
var a;
138149
var b;
139150
var y;
@@ -143,10 +154,14 @@ bench( pkg+'::set:b', function benchmark( bm ) {
143154
b = 55.54321;
144155
dist = new Kumaraswamy( a, b );
145156

157+
opts = {
158+
'dtype': 'float64'
159+
};
160+
y = uniform( 100, EPS, 100.0, opts );
161+
146162
bm.tic();
147163
for ( i = 0; i < bm.iterations; i++ ) {
148-
y = ( 100.0*randu() ) + EPS;
149-
dist.b = y;
164+
dist.b = y[ i % y.length ];
150165
if ( dist.b !== y ) {
151166
bm.fail( 'should return set value' );
152167
}
@@ -161,18 +176,25 @@ bench( pkg+'::set:b', function benchmark( bm ) {
161176

162177
bench( pkg+':kurtosis', function benchmark( bm ) {
163178
var dist;
179+
var opts;
164180
var a;
165181
var b;
182+
var x;
166183
var y;
167184
var i;
168185

169186
a = 100.56789;
170187
b = 55.54321;
171188
dist = new Kumaraswamy( a, b );
172189

190+
opts = {
191+
'dtype': 'float64'
192+
};
193+
x = uniform( 100, EPS, 100.0, opts );
194+
173195
bm.tic();
174196
for ( i = 0; i < bm.iterations; i++ ) {
175-
dist.a = ( 100.0*randu() ) + EPS;
197+
dist.a = x[ i % x.length ];
176198
y = dist.kurtosis;
177199
if ( isnan( y ) ) {
178200
bm.fail( 'should not return NaN' );
@@ -188,18 +210,25 @@ bench( pkg+':kurtosis', function benchmark( bm ) {
188210

189211
bench( pkg+':mean', function benchmark( bm ) {
190212
var dist;
213+
var opts;
191214
var a;
192215
var b;
216+
var x;
193217
var y;
194218
var i;
195219

196220
a = 100.56789;
197221
b = 55.54321;
198222
dist = new Kumaraswamy( a, b );
199223

224+
opts = {
225+
'dtype': 'float64'
226+
};
227+
x = uniform( 100, EPS, 100.0, opts );
228+
200229
bm.tic();
201230
for ( i = 0; i < bm.iterations; i++ ) {
202-
dist.a = ( 100.0*randu() ) + EPS;
231+
dist.a = x[ i % x.length ];
203232
y = dist.mean;
204233
if ( isnan( y ) ) {
205234
bm.fail( 'should not return NaN' );
@@ -215,18 +244,25 @@ bench( pkg+':mean', function benchmark( bm ) {
215244

216245
bench( pkg+':mode', function benchmark( bm ) {
217246
var dist;
247+
var opts;
218248
var a;
219249
var b;
250+
var x;
220251
var y;
221252
var i;
222253

223254
a = 100.56789;
224255
b = 55.54321;
225256
dist = new Kumaraswamy( a, b );
226257

258+
opts = {
259+
'dtype': 'float64'
260+
};
261+
x = uniform( 100, EPS + 1.0, 100.0, opts );
262+
227263
bm.tic();
228264
for ( i = 0; i < bm.iterations; i++ ) {
229-
dist.a = ( 100.0*randu() ) + 1.0 + EPS;
265+
dist.a = x[ i % x.length ];
230266
y = dist.mode;
231267
if ( isnan( y ) ) {
232268
bm.fail( 'should not return NaN' );
@@ -242,18 +278,25 @@ bench( pkg+':mode', function benchmark( bm ) {
242278

243279
bench( pkg+':skewness', function benchmark( bm ) {
244280
var dist;
281+
var opts;
245282
var a;
246283
var b;
284+
var x;
247285
var y;
248286
var i;
249287

250288
a = 100.56789;
251289
b = 55.54321;
252290
dist = new Kumaraswamy( a, b );
253291

292+
opts = {
293+
'dtype': 'float64'
294+
};
295+
x = uniform( 100, EPS, 100.0, opts );
296+
254297
bm.tic();
255298
for ( i = 0; i < bm.iterations; i++ ) {
256-
dist.a = ( 100.0*randu() ) + EPS;
299+
dist.a = x[ i % x.length ];
257300
y = dist.skewness;
258301
if ( isnan( y ) ) {
259302
bm.fail( 'should not return NaN' );
@@ -269,18 +312,25 @@ bench( pkg+':skewness', function benchmark( bm ) {
269312

270313
bench( pkg+':stdev', function benchmark( bm ) {
271314
var dist;
315+
var opts;
272316
var a;
273317
var b;
318+
var x;
274319
var y;
275320
var i;
276321

277322
a = 100.56789;
278323
b = 55.54321;
279324
dist = new Kumaraswamy( a, b );
280325

326+
opts = {
327+
'dtype': 'float64'
328+
};
329+
x = uniform( 100, EPS, 100.0, opts );
330+
281331
bm.tic();
282332
for ( i = 0; i < bm.iterations; i++ ) {
283-
dist.a = ( 100.0*randu() ) + EPS;
333+
dist.a = x[ i % x.length ];
284334
y = dist.stdev;
285335
if ( isnan( y ) ) {
286336
bm.fail( 'should not return NaN' );
@@ -296,18 +346,25 @@ bench( pkg+':stdev', function benchmark( bm ) {
296346

297347
bench( pkg+':variance', function benchmark( bm ) {
298348
var dist;
349+
var opts;
299350
var a;
300351
var b;
352+
var x;
301353
var y;
302354
var i;
303355

304356
a = 100.56789;
305357
b = 55.54321;
306358
dist = new Kumaraswamy( a, b );
307359

360+
opts = {
361+
'dtype': 'float64'
362+
};
363+
x = uniform( 100, EPS, 100.0, opts );
364+
308365
bm.tic();
309366
for ( i = 0; i < bm.iterations; i++ ) {
310-
dist.a = ( 100.0*randu() ) + EPS;
367+
dist.a = x[ i % x.length ];
311368
y = dist.variance;
312369
if ( isnan( y ) ) {
313370
bm.fail( 'should not return NaN' );
@@ -323,6 +380,7 @@ bench( pkg+':variance', function benchmark( bm ) {
323380

324381
bench( pkg+':cdf', function benchmark( bm ) {
325382
var dist;
383+
var opts;
326384
var a;
327385
var b;
328386
var x;
@@ -333,10 +391,14 @@ bench( pkg+':cdf', function benchmark( bm ) {
333391
b = 55.54321;
334392
dist = new Kumaraswamy( a, b );
335393

394+
opts = {
395+
'dtype': 'float64'
396+
};
397+
x = uniform( 100, 0.0, 1.0, opts );
398+
336399
bm.tic();
337400
for ( i = 0; i < bm.iterations; i++ ) {
338-
x = randu();
339-
y = dist.cdf( x );
401+
y = dist.cdf( x[ i % x.length ] );
340402
if ( isnan( y ) ) {
341403
bm.fail( 'should not return NaN' );
342404
}
@@ -351,6 +413,7 @@ bench( pkg+':cdf', function benchmark( bm ) {
351413

352414
bench( pkg+':logcdf', function benchmark( bm ) {
353415
var dist;
416+
var opts;
354417
var a;
355418
var b;
356419
var x;
@@ -361,10 +424,14 @@ bench( pkg+':logcdf', function benchmark( bm ) {
361424
b = 55.54321;
362425
dist = new Kumaraswamy( a, b );
363426

427+
opts = {
428+
'dtype': 'float64'
429+
};
430+
x = uniform( 100, 0.0, 1.0, opts );
431+
364432
bm.tic();
365433
for ( i = 0; i < bm.iterations; i++ ) {
366-
x = randu();
367-
y = dist.logcdf( x );
434+
y = dist.logcdf( x[ i % x.length ] );
368435
if ( isnan( y ) ) {
369436
bm.fail( 'should not return NaN' );
370437
}
@@ -379,6 +446,7 @@ bench( pkg+':logcdf', function benchmark( bm ) {
379446

380447
bench( pkg+':logpdf', function benchmark( bm ) {
381448
var dist;
449+
var opts;
382450
var a;
383451
var b;
384452
var x;
@@ -389,10 +457,14 @@ bench( pkg+':logpdf', function benchmark( bm ) {
389457
b = 55.54321;
390458
dist = new Kumaraswamy( a, b );
391459

460+
opts = {
461+
'dtype': 'float64'
462+
};
463+
x = uniform( 100, 0.0, 1.0, opts );
464+
392465
bm.tic();
393466
for ( i = 0; i < bm.iterations; i++ ) {
394-
x = randu();
395-
y = dist.logpdf( x );
467+
y = dist.logpdf( x[ i % x.length ] );
396468
if ( isnan( y ) ) {
397469
bm.fail( 'should not return NaN' );
398470
}
@@ -407,6 +479,7 @@ bench( pkg+':logpdf', function benchmark( bm ) {
407479

408480
bench( pkg+':pdf', function benchmark( bm ) {
409481
var dist;
482+
var opts;
410483
var a;
411484
var b;
412485
var x;
@@ -417,10 +490,14 @@ bench( pkg+':pdf', function benchmark( bm ) {
417490
b = 55.54321;
418491
dist = new Kumaraswamy( a, b );
419492

493+
opts = {
494+
'dtype': 'float64'
495+
};
496+
x = uniform( 100, 0.0, 1.0, opts );
497+
420498
bm.tic();
421499
for ( i = 0; i < bm.iterations; i++ ) {
422-
x = randu();
423-
y = dist.pdf( x );
500+
y = dist.pdf( x[ i % x.length ] );
424501
if ( isnan( y ) ) {
425502
bm.fail( 'should not return NaN' );
426503
}
@@ -435,6 +512,7 @@ bench( pkg+':pdf', function benchmark( bm ) {
435512

436513
bench( pkg+':quantile', function benchmark( bm ) {
437514
var dist;
515+
var opts;
438516
var a;
439517
var b;
440518
var x;
@@ -445,10 +523,14 @@ bench( pkg+':quantile', function benchmark( bm ) {
445523
b = 55.54321;
446524
dist = new Kumaraswamy( a, b );
447525

526+
opts = {
527+
'dtype': 'float64'
528+
};
529+
x = uniform( 100, 0.0, 1.0, opts );
530+
448531
bm.tic();
449532
for ( i = 0; i < bm.iterations; i++ ) {
450-
x = randu();
451-
y = dist.quantile( x );
533+
y = dist.quantile( x[ i % x.length ] );
452534
if ( isnan( y ) ) {
453535
bm.fail( 'should not return NaN' );
454536
}

0 commit comments

Comments
 (0)