Skip to content

Commit 2b6d616

Browse files
authored
bench: update random value generation
PR-URL: #6683 Reviewed-by: Athan Reines <[email protected]>
1 parent ef16301 commit 2b6d616

File tree

17 files changed

+96
-51
lines changed

17 files changed

+96
-51
lines changed

lib/node_modules/@stdlib/math/base/assert/is-negative-zero/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 isNegativeZero = require( './../lib' );
@@ -30,14 +30,19 @@ var isNegativeZero = 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 = isNegativeZero( x );
45+
y = isNegativeZero( 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-negative-zero/benchmark/benchmark.native.js

Lines changed: 8 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;
@@ -39,14 +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

47+
opts = {
48+
'dtype': 'float64'
49+
};
50+
x = uniform( 100, -5.0e6, 5.0e6, opts );
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1.0e7 ) - 5.0e6;
49-
y = isNegativeZero( x );
54+
y = isNegativeZero( x[ i%x.length ] );
5055
if ( typeof y !== 'boolean' ) {
5156
b.fail( 'should return a boolean' );
5257
}

lib/node_modules/@stdlib/math/base/assert/is-negative-zero/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ bool is_negative_zero( double x ) {
101101
*/
102102
static double benchmark( void ) {
103103
double elapsed;
104-
double x;
104+
double x[ 100 ];
105105
double t;
106106
bool y;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = ( 1.0e7*rand_double() ) - 5.0e6;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = ( 1.0e7*rand_double() ) - 5.0e6;
112-
y = is_negative_zero( x );
115+
y = is_negative_zero( x[ i%100 ] );
113116
if ( y != true && y != false ) {
114117
printf( "should return true or false\n" );
115118
break;

lib/node_modules/@stdlib/math/base/assert/is-negative-zero/benchmark/c/native/benchmark.c

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

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 1.0e7*rand_double() ) - 5.0e6;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = (rand_double()*1.0e7) - 5.0e6;
103-
b = stdlib_base_is_negative_zero( x );
106+
b = stdlib_base_is_negative_zero( x[ i%100 ] );
104107
if ( b != true && b != false ) {
105108
printf( "should return either true or false\n" );
106109
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ tape( 'main export is a function', function test( t ) {
3333
});
3434

3535
tape( 'the function returns `true` if provided `-0`', function test( t ) {
36-
t.equal( isNegativeZero( -0.0 ), true, 'returns true' );
36+
t.equal( isNegativeZero( -0.0 ), true, 'returns expected value' );
3737
t.end();
3838
});
3939

4040
tape( 'the function returns `false` if provided `+0`', function test( t ) {
41-
t.equal( isNegativeZero( +0.0 ), false, 'returns false' );
41+
t.equal( isNegativeZero( +0.0 ), false, 'returns expected value' );
4242
t.end();
4343
});
4444

@@ -61,7 +61,7 @@ tape( 'the function returns `false` if not provided `-0`', function test( t ) {
6161
];
6262

6363
for ( i = 0; i < values.length; i++ ) {
64-
t.equal( isNegativeZero( values[i] ), false, 'returns false if provided ' + values[ i ] );
64+
t.equal( isNegativeZero( values[i] ), false, 'returns expected value if provided ' + values[ i ] );
6565
}
6666
t.end();
6767
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ tape( 'main export is a function', opts, function test( t ) {
4242
});
4343

4444
tape( 'the function returns `true` if provided `-0`', opts, function test( t ) {
45-
t.equal( isNegativeZero( -0.0 ), true, 'returns true' );
45+
t.equal( isNegativeZero( -0.0 ), true, 'returns expected value' );
4646
t.end();
4747
});
4848

4949
tape( 'the function returns `false` if provided `+0`', opts, function test( t ) {
50-
t.equal( isNegativeZero( +0.0 ), false, 'returns false' );
50+
t.equal( isNegativeZero( +0.0 ), false, 'returns expected value' );
5151
t.end();
5252
});
5353

@@ -70,7 +70,7 @@ tape( 'the function returns `false` if not provided `-0`', opts, function test(
7070
];
7171

7272
for ( i = 0; i < values.length; i++ ) {
73-
t.equal( isNegativeZero( values[i] ), false, 'returns false if provided ' + values[ i ] );
73+
t.equal( isNegativeZero( values[i] ), false, 'returns expected value if provided ' + values[ i ] );
7474
}
7575
t.end();
7676
});

lib/node_modules/@stdlib/math/base/assert/is-negative-zerof/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 isNegativeZerof = require( './../lib' );
@@ -30,14 +30,19 @@ var isNegativeZerof = 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': 'float32'
40+
};
41+
x = uniform( 100, -50.0, 50.0, opts );
42+
3743
b.tic();
3844
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*100.0 ) - 50.0;
40-
y = isNegativeZerof( x );
45+
y = isNegativeZerof( 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-negative-zerof/benchmark/benchmark.native.js

Lines changed: 8 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;
@@ -39,14 +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

47+
opts = {
48+
'dtype': 'float32'
49+
};
50+
x = uniform( 100, -50.0, 50.0, opts );
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*100.0 ) - 50.0;
49-
y = isNegativeZerof( x );
54+
y = isNegativeZerof( x[ i%x.length ] );
5055
if ( typeof y !== 'boolean' ) {
5156
b.fail( 'should return a boolean' );
5257
}

lib/node_modules/@stdlib/math/base/assert/is-negative-zerof/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ bool is_negative_zerof( float x ) {
101101
*/
102102
static double benchmark( void ) {
103103
double elapsed;
104+
float x[ 100 ];
104105
double t;
105-
float x;
106106
bool y;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = ( 100.0f*rand_float() ) - 50.0f;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = ( 100.0f*rand_float() ) - 50.0f;
112-
y = is_negative_zerof( x );
115+
y = is_negative_zerof( x[ i%100 ] );
113116
if ( y != true && y != false ) {
114117
printf( "should return true or false\n" );
115118
break;

lib/node_modules/@stdlib/math/base/assert/is-negative-zerof/benchmark/c/native/benchmark.c

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

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 100.0f*rand_float() ) - 50.0f;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = (rand_float()*100.0f) - 50.0f;
103-
b = stdlib_base_is_negative_zerof( x );
106+
b = stdlib_base_is_negative_zerof( x[ i%100 ] );
104107
if ( b != true && b != false ) {
105108
printf( "should return either true or false\n" );
106109
break;

0 commit comments

Comments
 (0)