Skip to content

Commit c912eff

Browse files
authored
bench: update random value generation
PR-URL: #6676 Reviewed-by: Athan Reines <[email protected]>
1 parent 8356484 commit c912eff

File tree

14 files changed

+95
-68
lines changed

14 files changed

+95
-68
lines changed

lib/node_modules/@stdlib/math/base/assert/is-even/benchmark/benchmark.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ var isEven = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33-
var len;
33+
var opts;
3434
var x;
3535
var y;
3636
var i;
3737

38-
len = 100;
39-
x = discreteUniform( len, 0, 1000 );
38+
opts = {
39+
'dtype': 'float64'
40+
};
41+
x = discreteUniform( 100, 0, 1000, opts );
4042

4143
b.tic();
4244
for ( i = 0; i < b.iterations; i++ ) {
43-
y = isEven( x[ i % len ] );
45+
y = isEven( x[ i % x.length ] );
4446
if ( typeof y !== 'boolean' ) {
4547
b.fail( 'should return a boolean' );
4648
}

lib/node_modules/@stdlib/math/base/assert/is-even/benchmark/benchmark.native.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42-
var len;
42+
var opts;
4343
var x;
4444
var y;
4545
var i;
4646

47-
len = 100;
48-
x = discreteUniform( len, 0, 1000 );
47+
opts = {
48+
'dtype': 'float64'
49+
};
50+
x = discreteUniform( 100, 0, 1000, opts );
4951

5052
b.tic();
5153
for ( i = 0; i < b.iterations; i++ ) {
52-
y = isEven( x[ i % len ] );
54+
y = isEven( x[ i % x.length ] );
5355
if ( typeof y !== 'boolean' ) {
5456
b.fail( 'should return a boolean' );
5557
}

lib/node_modules/@stdlib/math/base/assert/is-even/test/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tape( 'the function returns `true` if provided an even number', function test( t
4444
x = round( randu()*1.0e6 ) - 5.0e5;
4545
x *= 2; // always even
4646
bool = isEven( x );
47-
t.equal( bool, true, 'returns true when provided '+x );
47+
t.equal( bool, true, 'returns expected value when provided '+x );
4848
}
4949
t.end();
5050
});
@@ -59,29 +59,29 @@ tape( 'the function returns `false` if provided an odd number', function test( t
5959
x += 1;
6060
}
6161
bool = isEven( x );
62-
t.equal( bool, false, 'returns false when provided '+x );
62+
t.equal( bool, false, 'returns expected value when provided '+x );
6363
}
6464
t.end();
6565
});
6666

6767
tape( 'the function returns `true` if provided `+-0`', function test( t ) {
68-
t.equal( isEven( +0.0 ), true, 'returns true' );
69-
t.equal( isEven( -0.0 ), true, 'returns true' );
68+
t.equal( isEven( +0.0 ), true, 'returns expected value' );
69+
t.equal( isEven( -0.0 ), true, 'returns expected value' );
7070
t.end();
7171
});
7272

7373
tape( 'WARNING: the function returns `true` if provided `+infinity`', function test( t ) {
74-
t.equal( isEven( PINF ), true, 'returns true' );
74+
t.equal( isEven( PINF ), true, 'returns expected value' );
7575
t.end();
7676
});
7777

7878
tape( 'WARNING: the function returns `true` if provided `-infinity`', function test( t ) {
79-
t.equal( isEven( NINF ), true, 'returns true' );
79+
t.equal( isEven( NINF ), true, 'returns expected value' );
8080
t.end();
8181
});
8282

8383
tape( 'the function returns `false` if provided `NaN`', function test( t ) {
84-
t.equal( isEven( NaN ), false, 'returns false' );
85-
t.equal( isEven( 0.0/0.0 ), false, 'returns false' );
84+
t.equal( isEven( NaN ), false, 'returns expected value' );
85+
t.equal( isEven( 0.0/0.0 ), false, 'returns expected value' );
8686
t.end();
8787
});

lib/node_modules/@stdlib/math/base/assert/is-even/test/test.native.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tape( 'the function returns `true` if provided an even number', opts, function t
5353
x = round( randu()*1.0e6 ) - 5.0e5;
5454
x *= 2; // always even
5555
bool = isEven( x );
56-
t.equal( bool, true, 'returns true when provided '+x );
56+
t.equal( bool, true, 'returns expected value when provided '+x );
5757
}
5858
t.end();
5959
});
@@ -68,29 +68,29 @@ tape( 'the function returns `false` if provided an odd number', opts, function t
6868
x += 1;
6969
}
7070
bool = isEven( x );
71-
t.equal( bool, false, 'returns false when provided '+x );
71+
t.equal( bool, false, 'returns expected value when provided '+x );
7272
}
7373
t.end();
7474
});
7575

7676
tape( 'the function returns `true` if provided `+-0`', opts, function test( t ) {
77-
t.equal( isEven( +0.0 ), true, 'returns true' );
78-
t.equal( isEven( -0.0 ), true, 'returns true' );
77+
t.equal( isEven( +0.0 ), true, 'returns expected value' );
78+
t.equal( isEven( -0.0 ), true, 'returns expected value' );
7979
t.end();
8080
});
8181

8282
tape( 'WARNING: the function returns `true` if provided `+infinity`', opts, function test( t ) {
83-
t.equal( isEven( PINF ), true, 'returns true' );
83+
t.equal( isEven( PINF ), true, 'returns expected value' );
8484
t.end();
8585
});
8686

8787
tape( 'WARNING: the function returns `true` if provided `-infinity`', opts, function test( t ) {
88-
t.equal( isEven( NINF ), true, 'returns true' );
88+
t.equal( isEven( NINF ), true, 'returns expected value' );
8989
t.end();
9090
});
9191

9292
tape( 'the function returns `false` if provided `NaN`', opts, function test( t ) {
93-
t.equal( isEven( NaN ), false, 'returns false' );
94-
t.equal( isEven( 0.0/0.0 ), false, 'returns false' );
93+
t.equal( isEven( NaN ), false, 'returns expected value' );
94+
t.equal( isEven( 0.0/0.0 ), false, 'returns expected value' );
9595
t.end();
9696
});

lib/node_modules/@stdlib/math/base/assert/is-evenf/benchmark/benchmark.js

Lines changed: 7 additions & 3 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/array/discrete-uniform' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2525
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var pkg = require( './../package.json' ).name;
2727
var isEvenf = require( './../lib' );
@@ -30,15 +30,19 @@ var isEvenf = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var opts;
3334
var x;
3435
var y;
3536
var i;
3637

37-
x = randu( 100, -50, 50 );
38+
opts = {
39+
'dtype': 'float32'
40+
};
41+
x = discreteUniform( 100, -50, 50, opts );
3842

3943
b.tic();
4044
for ( i = 0; i < b.iterations; i++ ) {
41-
y = isEvenf( x[ i % 100 ] );
45+
y = isEvenf( x[ i % x.length ] );
4246
if ( typeof y !== 'boolean' ) {
4347
b.fail( 'should return a boolean' );
4448
}

lib/node_modules/@stdlib/math/base/assert/is-evenf/benchmark/benchmark.native.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/discrete-uniform' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2626
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -39,15 +39,19 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
4243
var x;
4344
var y;
4445
var i;
4546

46-
x = randu( 100, -50, 50 );
47+
opts = {
48+
'dtype': 'float32'
49+
};
50+
x = discreteUniform( 100, -50, 50, opts );
4751

4852
b.tic();
4953
for ( i = 0; i < b.iterations; i++ ) {
50-
y = isEvenf( x[ i % 100 ] );
54+
y = isEvenf( x[ i % x.length ] );
5155
if ( typeof y !== 'boolean' ) {
5256
b.fail( 'should return a boolean' );
5357
}

lib/node_modules/@stdlib/math/base/assert/is-evenf/test/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tape( 'the function returns `true` if provided an even number', function test( t
4444
x = roundf( randu() * 1.0e6 ) - 5.0e5;
4545
x *= 2; // always even
4646
bool = isEvenf( x );
47-
t.equal( bool, true, 'returns true when provided '+x );
47+
t.equal( bool, true, 'returns expected value when provided '+x );
4848
}
4949
t.end();
5050
});
@@ -59,29 +59,29 @@ tape( 'the function returns `false` if provided an odd number', function test( t
5959
x += 1;
6060
}
6161
bool = isEvenf( x );
62-
t.equal( bool, false, 'returns false when provided '+x );
62+
t.equal( bool, false, 'returns expected value when provided '+x );
6363
}
6464
t.end();
6565
});
6666

6767
tape( 'the function returns `true` if provided `+-0`', function test( t ) {
68-
t.equal( isEvenf( +0.0 ), true, 'returns true' );
69-
t.equal( isEvenf( -0.0 ), true, 'returns true' );
68+
t.equal( isEvenf( +0.0 ), true, 'returns expected value' );
69+
t.equal( isEvenf( -0.0 ), true, 'returns expected value' );
7070
t.end();
7171
});
7272

7373
tape( 'WARNING: the function returns `true` if provided `+infinity`', function test( t ) {
74-
t.equal( isEvenf( PINF ), true, 'returns true' );
74+
t.equal( isEvenf( PINF ), true, 'returns expected value' );
7575
t.end();
7676
});
7777

7878
tape( 'WARNING: the function returns `true` if provided `-infinity`', function test( t ) {
79-
t.equal( isEvenf( NINF ), true, 'returns true' );
79+
t.equal( isEvenf( NINF ), true, 'returns expected value' );
8080
t.end();
8181
});
8282

8383
tape( 'the function returns `false` if provided `NaN`', function test( t ) {
84-
t.equal( isEvenf( NaN ), false, 'returns false' );
85-
t.equal( isEvenf( 0.0 / 0.0 ), false, 'returns false' );
84+
t.equal( isEvenf( NaN ), false, 'returns expected value' );
85+
t.equal( isEvenf( 0.0 / 0.0 ), false, 'returns expected value' );
8686
t.end();
8787
});

lib/node_modules/@stdlib/math/base/assert/is-evenf/test/test.native.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tape( 'the function returns `true` if provided an even number', opts, function t
5353
x = roundf( randu() * 1.0e6 ) - 5.0e5;
5454
x *= 2; // always even
5555
bool = isEvenf( x );
56-
t.equal( bool, true, 'returns true when provided '+x );
56+
t.equal( bool, true, 'returns expected value when provided '+x );
5757
}
5858
t.end();
5959
});
@@ -68,29 +68,29 @@ tape( 'the function returns `false` if provided an odd number', opts, function t
6868
x += 1;
6969
}
7070
bool = isEvenf( x );
71-
t.equal( bool, false, 'returns false when provided '+x );
71+
t.equal( bool, false, 'returns expected value when provided '+x );
7272
}
7373
t.end();
7474
});
7575

7676
tape( 'the function returns `true` if provided `+-0`', opts, function test( t ) {
77-
t.equal( isEvenf( +0.0 ), true, 'returns true' );
78-
t.equal( isEvenf( -0.0 ), true, 'returns true' );
77+
t.equal( isEvenf( +0.0 ), true, 'returns expected value' );
78+
t.equal( isEvenf( -0.0 ), true, 'returns expected value' );
7979
t.end();
8080
});
8181

8282
tape( 'WARNING: the function returns `true` if provided `+infinity`', opts, function test( t ) {
83-
t.equal( isEvenf( PINF ), true, 'returns true' );
83+
t.equal( isEvenf( PINF ), true, 'returns expected value' );
8484
t.end();
8585
});
8686

8787
tape( 'WARNING: the function returns `true` if provided `-infinity`', opts, function test( t ) {
88-
t.equal( isEvenf( NINF ), true, 'returns true' );
88+
t.equal( isEvenf( NINF ), true, 'returns expected value' );
8989
t.end();
9090
});
9191

9292
tape( 'the function returns `false` if provided `NaN`', opts, function test( t ) {
93-
t.equal( isEvenf( NaN ), false, 'returns false' );
94-
t.equal( isEvenf( 0.0 / 0.0 ), false, 'returns false' );
93+
t.equal( isEvenf( NaN ), false, 'returns expected value' );
94+
t.equal( isEvenf( 0.0 / 0.0 ), false, 'returns expected value' );
9595
t.end();
9696
});

lib/node_modules/@stdlib/math/base/assert/is-finite/benchmark/benchmark.js

Lines changed: 8 additions & 3 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var pkg = require( './../package.json' ).name;
2727
var isfinite = require( './../lib' );
@@ -30,14 +30,19 @@ var isfinite = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var opts;
3334
var x;
3435
var y;
3536
var i;
3637

38+
opts = {
39+
'dtype': 'float64'
40+
};
41+
x = uniform( 100, -5.0e6, 5.0e6, opts );
42+
3743
b.tic();
3844
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1.0e7 ) - 5.0e6;
40-
y = isfinite( x );
45+
y = isfinite( x[ i%x.length ] );
4146
if ( typeof y !== 'boolean' ) {
4247
b.fail( 'should return a boolean' );
4348
}

lib/node_modules/@stdlib/math/base/assert/is-finite/benchmark/benchmark.native.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,14 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
opts = {
47+
'dtype': 'float64'
48+
};
49+
x = uniform( 100, -5.0e6, 5.0e6, opts );
50+
4651
b.tic();
4752
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1.0e7 ) - 5.0e6;
49-
y = isfinite( x );
53+
y = isfinite( x[ i%x.length ] );
5054
if ( typeof y !== 'boolean' ) {
5155
b.fail( 'should return a boolean' );
5256
}

0 commit comments

Comments
 (0)