Skip to content

Commit 4039ae0

Browse files
bench: update random value generation
PR-URL: #5466 Reviewed-by: Athan Reines <[email protected]>
1 parent dfc7be6 commit 4039ae0

File tree

19 files changed

+119
-104
lines changed

19 files changed

+119
-104
lines changed

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

Lines changed: 3 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/uniform' );
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 trunc = require( './../lib' );
@@ -41,7 +41,7 @@ bench( pkg, function benchmark( b ) {
4141
var y;
4242
var i;
4343

44-
x = randu( 100, -500.0, 500.0 );
44+
x = uniform( 100, -500.0, 500.0 );
4545

4646
b.tic();
4747
for ( i = 0; i < b.iterations; i++ ) {
@@ -63,7 +63,7 @@ bench( pkg+'::built-in', opts, function benchmark( b ) {
6363
var y;
6464
var i;
6565

66-
x = randu( 100, -500.0, 500.0 );
66+
x = uniform( 100, -500.0, 500.0 );
6767

6868
b.tic();
6969
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 2 additions & 2 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/uniform' );
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,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 100, -500.0, 500.0 );
46+
x = uniform( 100, -500.0, 500.0 );
4747

4848
b.tic();
4949
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static double benchmark( void ) {
101101

102102
t = tic();
103103
for ( i = 0; i < ITERATIONS; i++ ) {
104-
y = trunc( x[ i % 100 ] );
104+
y = trunc( x[ i%100 ] );
105105
if ( y != y ) {
106106
printf( "should not return NaN\n" );
107107
break;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static double benchmark( void ) {
102102

103103
t = tic();
104104
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_trunc( x[ i % 100 ] );
105+
y = stdlib_base_trunc( x[ i%100 ] );
106106
if ( y != y ) {
107107
printf( "should not return NaN\n" );
108108
break;

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

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

37+
x = uniform( 100, -5.0e6, 5.0e6 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1.0e7 ) - 5.0e6;
40-
y = trunc10( x );
41+
y = trunc10( x[ i % x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}

lib/node_modules/@stdlib/math/base/special/trunc10/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, -5.0e6, 5.0e6 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu() * 1.0e7 ) - 5.0e6;
49-
y = trunc10( x );
50+
y = trunc10( x[ i % x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,35 @@ tape( 'the function returns `+0` if provided `+0`', function test( t ) {
4242
var v;
4343

4444
v = trunc10( 0.0 );
45-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
45+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
4646

4747
v = trunc10( +0.0 );
48-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
48+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
4949

5050
t.end();
5151
});
5252

5353
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
5454
var v = trunc10( -0.0 );
55-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
55+
t.strictEqual( isNegativeZero( 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 = trunc10( 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 v = trunc10( PINF );
67-
t.strictEqual( v, PINF, 'returns +infinity' );
67+
t.strictEqual( v, PINF, 'returns expected value' );
6868
t.end();
6969
});
7070

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

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
5151
var v;
5252

5353
v = trunc10( 0.0 );
54-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
54+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
5555

5656
v = trunc10( +0.0 );
57-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
57+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
5858

5959
t.end();
6060
});
6161

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

@@ -73,13 +73,13 @@ tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t )
7373

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

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

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

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

37+
x = uniform( 100, -5.0e6, 5.0e6 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1.0e7 ) - 5.0e6;
40-
y = trunc2( x );
41+
y = trunc2( x[ i % x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}

0 commit comments

Comments
 (0)