Skip to content

Commit 3b07561

Browse files
authored
bench: update random value generation
PR-URL: #6659 Reviewed-by: Athan Reines <[email protected]>
1 parent 3ed293c commit 3b07561

File tree

10 files changed

+56
-34
lines changed

10 files changed

+56
-34
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25-
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2625
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2726
var pkg = require( './../package.json' ).name;
2827
var isEven = require( './../lib' );
@@ -31,14 +30,19 @@ var isEven = require( './../lib' );
3130
// MAIN //
3231

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

38+
opts = {
39+
'dtype': 'int32'
40+
};
41+
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );
42+
3843
b.tic();
3944
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*1.0e7 ) - 5.0e6;
41-
y = isEven( float64ToInt32( x ) );
45+
y = isEven( x[ i%x.length ] );
4246
if ( typeof y !== 'boolean' ) {
4347
b.fail( 'should return a boolean' );
4448
}

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2726
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2827
var tryRequire = require( '@stdlib/utils/try-require' );
2928
var pkg = require( './../package.json' ).name;
@@ -40,14 +39,19 @@ var opts = {
4039
// MAIN //
4140

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

47+
opts = {
48+
'dtype': 'int32'
49+
};
50+
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );
51+
4752
b.tic();
4853
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*1.0e7 ) - 5.0e6;
50-
y = iseven( float64ToInt32( x ) );
54+
y = iseven( x[ i%x.length ] );
5155
if ( typeof y !== 'boolean' ) {
5256
b.fail( 'should return a boolean' );
5357
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ static double rand_double( void ) {
9393
*/
9494
static double benchmark( void ) {
9595
double elapsed;
96-
double x;
96+
double x[ 100 ];
9797
double t;
9898
bool b;
9999
int i;
100100

101+
for ( i = 0; i < 100; i++ ) {
102+
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
103+
}
104+
101105
t = tic();
102106
for ( i = 0; i < ITERATIONS; i++ ) {
103-
x = ( rand_double() * 200.0 ) - 100.0;
104-
b = stdlib_base_int32_is_even( (int32_t)x );
107+
b = stdlib_base_int32_is_even( (int32_t)x[ i%100 ] );
105108
if ( b != true && b != false ) {
106109
printf( "should return either true or false\n" );
107110
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tape( 'main export is a function', function test( t ) {
4343

4444
tape( 'the function returns `true` if provided `0`', function test( t ) {
4545
var bool = isEven( 0 );
46-
t.strictEqual( bool, true, 'returns true when provided 0' );
46+
t.strictEqual( bool, true, 'returns expected value' );
4747
t.end();
4848
});
4949

@@ -55,7 +55,7 @@ tape( 'the function returns `true` if provided an even integer', function test(
5555
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
5656
x *= 2; // always even
5757
bool = isEven( x );
58-
t.strictEqual( bool, true, 'returns true when provided '+x );
58+
t.strictEqual( bool, true, 'returns expected value when provided '+x );
5959
}
6060
t.end();
6161
});
@@ -73,7 +73,7 @@ tape( 'the function returns `false` if provided an odd integer', function test(
7373
x += 1;
7474
}
7575
bool = isEven( x );
76-
t.strictEqual( bool, false, 'returns false when provided '+x );
76+
t.strictEqual( bool, false, 'returns expected value when provided '+x );
7777
}
7878
t.end();
7979
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tape( 'main export is a function', opts, function test( t ) {
4848

4949
tape( 'the function returns `true` if provided `0`', opts, function test( t ) {
5050
var bool = iseven( 0 );
51-
t.strictEqual( bool, true, 'returns true when provided 0' );
51+
t.strictEqual( bool, true, 'returns expected value' );
5252
t.end();
5353
});
5454

@@ -60,7 +60,7 @@ tape( 'the function returns `true` if provided an even integer', opts, function
6060
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
6161
x *= 2; // always even
6262
bool = iseven( x );
63-
t.strictEqual( bool, true, 'returns true when provided '+x );
63+
t.strictEqual( bool, true, 'returns expected value when provided '+x );
6464
}
6565
t.end();
6666
});
@@ -78,7 +78,7 @@ tape( 'the function returns `false` if provided an odd integer', opts, function
7878
x += 1;
7979
}
8080
bool = iseven( x );
81-
t.strictEqual( bool, false, 'returns false when provided '+x );
81+
t.strictEqual( bool, false, 'returns expected value when provided '+x );
8282
}
8383
t.end();
8484
});

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25-
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2625
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2726
var pkg = require( './../package.json' ).name;
2827
var isOdd = require( './../lib' );
@@ -31,14 +30,19 @@ var isOdd = require( './../lib' );
3130
// MAIN //
3231

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

38+
opts = {
39+
'dtype': 'int32'
40+
};
41+
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );
42+
3843
b.tic();
3944
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*1.0e7 ) - 5.0e6;
41-
y = isOdd( float64ToInt32( x ) );
45+
y = isOdd( x[ i%x.length ] );
4246
if ( typeof y !== 'boolean' ) {
4347
b.fail( 'should return a boolean' );
4448
}

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2726
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2827
var tryRequire = require( '@stdlib/utils/try-require' );
2928
var pkg = require( './../package.json' ).name;
@@ -40,14 +39,19 @@ var opts = {
4039
// MAIN //
4140

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

47+
opts = {
48+
'dtype': 'int32'
49+
};
50+
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );
51+
4752
b.tic();
4853
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*1.0e7 ) - 5.0e6;
50-
y = isOdd( float64ToInt32( x ) );
54+
y = isOdd( x[ i%x.length ] );
5155
if ( typeof y !== 'boolean' ) {
5256
b.fail( 'should return a boolean' );
5357
}

lib/node_modules/@stdlib/math/base/assert/int32-is-odd/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ static double rand_double( void ) {
9393
*/
9494
static double benchmark( void ) {
9595
double elapsed;
96-
double x;
96+
double x[ 100 ];
9797
double t;
9898
bool b;
9999
int i;
100100

101+
for ( i = 0; i < 100; i++ ) {
102+
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
103+
}
104+
101105
t = tic();
102106
for ( i = 0; i < ITERATIONS; i++ ) {
103-
x = ( rand_double() * 200.0 ) - 100.0;
104-
b = stdlib_base_int32_is_odd( (int32_t)x );
107+
b = stdlib_base_int32_is_odd( (int32_t)x[ i%100 ] );
105108
if ( b != true && b != false ) {
106109
printf( "should return either true or false\n" );
107110
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tape( 'main export is a function', function test( t ) {
4343

4444
tape( 'the function returns `false` if provided `0`', function test( t ) {
4545
var bool = isOdd( 0 );
46-
t.strictEqual( bool, false, 'returns false when provided 0' );
46+
t.strictEqual( bool, false, 'returns expected value' );
4747
t.end();
4848
});
4949

@@ -55,7 +55,7 @@ tape( 'the function returns `false` if provided an even integer', function test(
5555
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
5656
x *= 2; // always even
5757
bool = isOdd( x );
58-
t.strictEqual( bool, false, 'returns false when provided '+x );
58+
t.strictEqual( bool, false, 'returns expected value when provided '+x );
5959
}
6060
t.end();
6161
});
@@ -73,7 +73,7 @@ tape( 'the function returns `true` if provided an odd integer', function test( t
7373
x += 1;
7474
}
7575
bool = isOdd( x );
76-
t.strictEqual( bool, true, 'returns true when provided '+x );
76+
t.strictEqual( bool, true, 'returns expected value when provided '+x );
7777
}
7878
t.end();
7979
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tape( 'main export is a function', opts, function test( t ) {
4848

4949
tape( 'the function returns `false` if provided `0`', opts, function test( t ) {
5050
var bool = isOdd( 0 );
51-
t.strictEqual( bool, false, 'returns false when provided 0' );
51+
t.strictEqual( bool, false, 'returns expected value' );
5252
t.end();
5353
});
5454

@@ -60,7 +60,7 @@ tape( 'the function returns `false` if provided an even integer', opts, function
6060
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
6161
x *= 2; // always even
6262
bool = isOdd( x );
63-
t.strictEqual( bool, false, 'returns false when provided '+x );
63+
t.strictEqual( bool, false, 'returns expected value when provided '+x );
6464
}
6565
t.end();
6666
});
@@ -78,7 +78,7 @@ tape( 'the function returns `true` if provided an odd integer', opts, function t
7878
x += 1;
7979
}
8080
bool = isOdd( x );
81-
t.strictEqual( bool, true, 'returns true when provided '+x );
81+
t.strictEqual( bool, true, 'returns expected value when provided '+x );
8282
}
8383
t.end();
8484
});

0 commit comments

Comments
 (0)