-
-
Notifications
You must be signed in to change notification settings - Fork 862
bench: update random value generation #7748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 12 commits
8e7ee5f
be9aefb
a894b4c
868dfc0
16e6b04
71ad4a5
6388c74
c3b1426
1e2a115
f6edeca
f61eeee
9f90179
c78d405
8938212
71fa049
692aea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,9 +21,10 @@ | |||||
// MODULES // | ||||||
|
||||||
var bench = require( '@stdlib/bench' ); | ||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||
var pkg = require( './../package.json' ).name; | ||||||
var Triangular = require( './../lib' ); | ||||||
|
||||||
|
@@ -32,16 +33,27 @@ var Triangular = require( './../lib' ); | |||||
|
||||||
bench( pkg+'::instantiation', function benchmark( bm ) { | ||||||
var dist; | ||||||
var as = new Float64Array(bm.iterations); | ||||||
var bs = new Float64Array(bm.iterations); | ||||||
var cs = new Float64Array(bm.iterations); | ||||||
var a; | ||||||
var b; | ||||||
var c; | ||||||
var i; | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
a = uniform(EPS, 10.0); | ||||||
b = uniform(a + EPS, a + 10.0); | ||||||
c = uniform(a, b); | ||||||
as[i] = a; | ||||||
bs[i] = b; | ||||||
cs[i] = c; | ||||||
} | ||||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
a = ( randu() * 10.0 ) + EPS; | ||||||
b = ( randu() * 10.0 ) + a + EPS; | ||||||
c = ( randu() * ( b-a ) ) + a; | ||||||
a = as[i]; | ||||||
b = bs[i]; | ||||||
c = cs[i]; | ||||||
dist = new Triangular( a, b, c ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
After the above changes have been made. |
||||||
if ( !( dist instanceof Triangular ) ) { | ||||||
bm.fail( 'should return a distribution instance' ); | ||||||
|
@@ -98,7 +110,7 @@ bench( pkg+'::set:a', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
y = ( 100.0*randu() ) + EPS; | ||||||
y = uniform(EPS, 100.0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be moved outside the benchmarking loop, similar to what's being done above. |
||||||
dist.a = y; | ||||||
if ( dist.a !== y ) { | ||||||
bm.fail( 'should return set value' ); | ||||||
|
@@ -155,7 +167,7 @@ bench( pkg+'::set:b', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
y = ( 100.0*randu() ) + c + EPS; | ||||||
y = uniform(EPS+c, 100.0+c+EPS); | ||||||
AryanJ18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
dist.b = y; | ||||||
if ( dist.b !== y ) { | ||||||
bm.fail( 'should return set value' ); | ||||||
|
@@ -212,7 +224,7 @@ bench( pkg+'::set:c', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
y = ( randu() * ( b-a ) ) + a; | ||||||
y = uniform(a, b); | ||||||
dist.c = y; | ||||||
if ( dist.c !== y ) { | ||||||
bm.fail( 'should return set value' ); | ||||||
|
@@ -241,7 +253,7 @@ bench( pkg+':entropy', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0, c); | ||||||
y = dist.entropy; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -270,7 +282,7 @@ bench( pkg+':kurtosis', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.kurtosis; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -299,7 +311,7 @@ bench( pkg+':mean', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.mean; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -328,7 +340,7 @@ bench( pkg+':median', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.median; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -357,7 +369,7 @@ bench( pkg+':skewness', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.skewness; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -386,7 +398,7 @@ bench( pkg+':stdev', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.stdev; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -415,7 +427,7 @@ bench( pkg+':variance', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
dist.a = randu() * c; | ||||||
dist.a = uniform(0.0, c); | ||||||
y = dist.variance; | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -445,7 +457,7 @@ bench( pkg+':cdf', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
x = randu() * 60.0; | ||||||
x = uniform(0.0, 60.0); | ||||||
y = dist.cdf( x ); | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -475,7 +487,7 @@ bench( pkg+':mgf', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
x = randu(); | ||||||
x = uniform(0.0, 1.0); | ||||||
y = dist.mgf( x ); | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -505,7 +517,7 @@ bench( pkg+':pdf', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
x = randu() * 60.0; | ||||||
x = uniform(0.0, 60.0); | ||||||
y = dist.pdf( x ); | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
@@ -535,7 +547,7 @@ bench( pkg+':quantile', function benchmark( bm ) { | |||||
|
||||||
bm.tic(); | ||||||
for ( i = 0; i < bm.iterations; i++ ) { | ||||||
x = randu(); | ||||||
x = uniform(0.0, 1.0); | ||||||
y = dist.quantile( x ); | ||||||
if ( isnan( y ) ) { | ||||||
bm.fail( 'should not return NaN' ); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,9 +22,9 @@ | |||||
|
||||||
var bench = require( '@stdlib/bench' ); | ||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||
var pkg = require( './../package.json' ).name; | ||||||
var entropy = require( './../lib' ); | ||||||
|
||||||
|
@@ -44,9 +44,9 @@ bench( pkg, function benchmark( b ) { | |||||
max = new Float64Array( len ); | ||||||
mode = new Float64Array( len ); | ||||||
for ( i = 0; i < len; i++ ) { | ||||||
min[ i ] = ( randu()*10.0 ); | ||||||
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS; | ||||||
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ]; | ||||||
min[ i ] = uniform( 0.0, 10.0 ); | ||||||
max[ i ] = uniform( min[ i ] + EPS, 10.0 + min[ i ] + EPS ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just to be consistent with the other benchmarks. This change applies throughout the PR. |
||||||
mode[ i ] = uniform( min[ i ], max[ i ] ); | ||||||
} | ||||||
|
||||||
b.tic(); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,10 @@ | |
var resolve = require( 'path' ).resolve; | ||
var bench = require( '@stdlib/bench' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||
var uniform = require( '@stdlib/random/base/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var tryRequire = require( '@stdlib/utils/try-require' ); | ||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||
var pkg = require( './../package.json' ).name; | ||
|
||
|
||
|
@@ -53,9 +53,9 @@ bench( pkg+'::native', opts, function benchmark( b ) { | |
max = new Float64Array( len ); | ||
mode = new Float64Array( len ); | ||
for ( i = 0; i < len; i++ ) { | ||
min[ i ] = ( randu()*10.0 ); | ||
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS; | ||
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ]; | ||
min[ i ] = uniform( 0.0, 10.0 ); | ||
max[ i ] = uniform( min[ i ] + EPS, 10.0 + min[ i ] + EPS ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. Rest looks good :) |
||
mode[ i ] = uniform( min[ i ], max[ i ] ); | ||
} | ||
|
||
b.tic(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed to follow what is done in https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/stats/base/dists/arcsine/ctor/benchmark/benchmark.js
Like: