Skip to content

Commit 1f50c39

Browse files
authored
bench: update random value generation
PR-URL: #6164 Reviewed-by: Athan Reines <[email protected]>
1 parent 6417ebc commit 1f50c39

File tree

14 files changed

+84
-54
lines changed

14 files changed

+84
-54
lines changed

lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.js

Lines changed: 7 additions & 5 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 pkg = require( './../package.json' ).name;
2727
var floor = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -500.0, 500.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1000.0 ) - 500.0;
40-
y = floor( x );
41+
y = floor( x[ i%x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}
@@ -55,10 +56,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
5556
var y;
5657
var i;
5758

59+
x = uniform( 100, -500.0, 500.0 );
60+
5861
b.tic();
5962
for ( i = 0; i < b.iterations; i++ ) {
60-
x = ( randu()*1000.0 ) - 500.0;
61-
y = Math.floor( x ); // eslint-disable-line stdlib/no-builtin-math
63+
y = Math.floor( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6264
if ( isnan( y ) ) {
6365
b.fail( 'should not return NaN' );
6466
}

lib/node_modules/@stdlib/math/base/special/floor/benchmark/benchmark.native.js

Lines changed: 4 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -500.0, 500.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1000.0 ) - 500.0;
49-
y = floor( x );
50+
y = floor( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
93+
double x[ 100 ];
9494
double y;
9595
double t;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = ( rand_double()*1000.0 ) - 500.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0*rand_double() ) - 500.0;
101-
y = floor( x );
104+
y = floor( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/cephes/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,18 @@ static double rand_double( void ) {
9595
*/
9696
static double benchmark( void ) {
9797
double elapsed;
98-
double x;
98+
double x[ 100 ];
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = ( rand_double()*1000.0 ) - 500.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 1000.0*rand_double() ) - 500.0;
106-
y = floor( x );
109+
y = floor( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

lib/node_modules/@stdlib/math/base/special/floor/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
94+
double x[ 100 ];
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 1000.0*rand_double() ) - 500.0;
102-
y = stdlib_base_floor( x );
105+
y = stdlib_base_floor( x[ i%100] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

lib/node_modules/@stdlib/math/base/special/floor/test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu
4646

4747
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
4848
var v = floor( -0.0 );
49-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
49+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
5050
t.end();
5151
});
5252

5353
tape( 'the function returns `+0` if provided `+0`', function test( t ) {
5454
var v = floor( +0.0 );
55-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
55+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
5656
t.end();
5757
});
5858

5959
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
6060
var v = floor( NaN );
61-
t.strictEqual( isnan( v ), true, 'returns NaN' );
61+
t.strictEqual( isnan( v ), true, 'returns expected value' );
6262
t.end();
6363
});
6464

6565
tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) {
6666
var val = floor( PINF );
67-
t.strictEqual( val, PINF, 'returns +infinity' );
67+
t.strictEqual( val, PINF, 'returns expected value' );
6868
t.end();
6969
});
7070

7171
tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) {
7272
var val = floor( NINF );
73-
t.strictEqual( val, NINF, 'returns -infinity' );
73+
t.strictEqual( val, NINF, 'returns expected value' );
7474
t.end();
7575
});

lib/node_modules/@stdlib/math/base/special/floor/test/test.native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,30 @@ tape( 'the function returns the largest integer less than or equal to a given nu
5555

5656
tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
5757
var v = floor( -0.0 );
58-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
58+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
5959
t.end();
6060
});
6161

6262
tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
6363
var v = floor( +0.0 );
64-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
64+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
6565
t.end();
6666
});
6767

6868
tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) {
6969
var v = floor( NaN );
70-
t.strictEqual( isnan( v ), true, 'returns NaN' );
70+
t.strictEqual( isnan( v ), true, 'returns expected value' );
7171
t.end();
7272
});
7373

7474
tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) {
7575
var val = floor( PINF );
76-
t.strictEqual( val, PINF, 'returns +infinity' );
76+
t.strictEqual( val, PINF, 'returns expected value' );
7777
t.end();
7878
});
7979

8080
tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) {
8181
var val = floor( NINF );
82-
t.strictEqual( val, NINF, 'returns -infinity' );
82+
t.strictEqual( val, NINF, 'returns expected value' );
8383
t.end();
8484
});

lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.js

Lines changed: 11 additions & 5 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var floorf = require( './../lib' );
@@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -500.0, 500, {
38+
'dtype': 'float32'
39+
});
40+
3741
b.tic();
3842
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1000.0 ) - 500.0;
40-
y = floorf( x );
43+
y = floorf( x[ i%x.length ] );
4144
if ( isnanf( y ) ) {
4245
b.fail( 'should not return NaN' );
4346
}
@@ -55,10 +58,13 @@ bench( pkg+'::built-in', function benchmark( b ) {
5558
var y;
5659
var i;
5760

61+
x = uniform( 100, -500.0, 500, {
62+
'dtype': 'float32'
63+
});
64+
5865
b.tic();
5966
for ( i = 0; i < b.iterations; i++ ) {
60-
x = ( randu()*1000.0 ) - 500.0;
61-
y = Math.floor( x ); // eslint-disable-line stdlib/no-builtin-math
67+
y = Math.floor( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6268
if ( isnanf( y ) ) {
6369
b.fail( 'should not return NaN' );
6470
}

lib/node_modules/@stdlib/math/base/special/floorf/benchmark/benchmark.native.js

Lines changed: 6 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -500.0, 500, {
47+
'dtype': 'float32'
48+
});
49+
4650
b.tic();
4751
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1000.0 ) - 500.0;
49-
y = floorf( x );
52+
y = floorf( x[ i%x.length ] );
5053
if ( isnanf( y ) ) {
5154
b.fail( 'should not return NaN' );
5255
}

lib/node_modules/@stdlib/math/base/special/floorf/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ static float rand_float( void ) {
9191
static double benchmark( void ) {
9292
double elapsed;
9393
double t;
94-
float x;
94+
float x[ 100 ];
9595
float y;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = ( rand_float()*1000.0f ) - 500.0f;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0f*rand_float() ) - 500.0f;
101-
y = floorf( x );
104+
y = floorf( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

0 commit comments

Comments
 (0)