Skip to content

Commit 07b51a4

Browse files
hrshyaPlaneshifter
andauthored
bench: update random value generation
PR-URL: #6378 Reviewed-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent b26c170 commit 07b51a4

File tree

21 files changed

+141
-116
lines changed

21 files changed

+141
-116
lines changed

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

+2-2
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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var pkg = require( './../package.json' ).name;
@@ -36,7 +36,7 @@ bench( pkg, function benchmark( b ) {
3636
var y;
3737
var i;
3838

39-
x = randu( 100, 1.0, 1000.0 );
39+
x = uniform( 100, 1.0, 1000.0 );
4040
base = discreteUniform( 100, 2.0, 10.0 );
4141

4242
b.tic();

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

+2-2
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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2727
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -45,7 +45,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4545
var y;
4646
var i;
4747

48-
x = randu( 100, 1.0, 1000.0 );
48+
x = uniform( 100, 1.0, 1000.0 );
4949
base = discreteUniform( 100, 2.0, 10.0 );
5050

5151
b.tic();

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

+4-3
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 logit = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

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

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

+4-3
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, 0.0, 1.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = randu();
49-
y = logit( x );
50+
y = logit( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ tape( 'main export is a function', function test( t ) {
4646

4747
tape( 'the function returns `NaN` when provided `NaN`', function test( t ) {
4848
var y = logit( NaN );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
t.end();
5151
});
5252

5353
tape( 'the function returns `NaN` when provided a number outside `[0,1]`', function test( t ) {
5454
var y = logit( 1.2 );
55-
t.equal( isnan( y ), true, 'returns NaN' );
55+
t.equal( isnan( y ), true, 'returns expected value' );
5656
y = logit( -0.1 );
57-
t.equal( isnan( y ), true, 'returns NaN' );
57+
t.equal( isnan( y ), true, 'returns expected value' );
5858
t.end();
5959
});
6060

6161
tape( 'the function returns `-Infinity` when provided `0`', function test( t ) {
6262
var y = logit( 0.0 );
63-
t.equal( y, NINF, 'returns -Infinity' );
63+
t.equal( y, NINF, 'returns expected value' );
6464
t.end();
6565
});
6666

6767
tape( 'the function returns `+Infinity` when provided `1`', function test( t ) {
6868
var y = logit( 1.0 );
69-
t.equal( y, PINF, 'returns +Infinity' );
69+
t.equal( y, PINF, 'returns expected value' );
7070
t.end();
7171
});
7272

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ tape( 'main export is a function', opts, function test( t ) {
5555

5656
tape( 'the function returns `NaN` when provided `NaN`', opts, function test( t ) {
5757
var y = logit( NaN );
58-
t.equal( isnan( y ), true, 'returns NaN' );
58+
t.equal( isnan( y ), true, 'returns expected value' );
5959
t.end();
6060
});
6161

6262
tape( 'the function returns `NaN` when provided a number outside `[0,1]`', opts, function test( t ) {
6363
var y = logit( 1.2 );
64-
t.equal( isnan( y ), true, 'returns NaN' );
64+
t.equal( isnan( y ), true, 'returns expected value' );
6565
y = logit( -0.1 );
66-
t.equal( isnan( y ), true, 'returns NaN' );
66+
t.equal( isnan( y ), true, 'returns expected value' );
6767
t.end();
6868
});
6969

7070
tape( 'the function returns `-Infinity` when provided `0`', opts, function test( t ) {
7171
var y = logit( 0.0 );
72-
t.equal( y, NINF, 'returns -Infinity' );
72+
t.equal( y, NINF, 'returns expected value' );
7373
t.end();
7474
});
7575

7676
tape( 'the function returns `+Infinity` when provided `1`', opts, function test( t ) {
7777
var y = logit( 1.0 );
78-
t.equal( y, PINF, 'returns +Infinity' );
78+
t.equal( y, PINF, 'returns expected value' );
7979
t.end();
8080
});
8181

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

+9-7
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 maxabs = require( './../lib' );
@@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
3535
var z;
3636
var i;
3737

38+
x = uniform( 100, -500.0, 500.0 );
39+
y = uniform( 100, -500.0, 500.0 );
40+
3841
b.tic();
3942
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*1000.0 ) - 500.0;
41-
y = ( randu()*1000.0 ) - 500.0;
42-
z = maxabs( x, y );
43+
z = maxabs( x[ i%x.length ], y[ i%y.length ] );
4344
if ( isnan( z ) ) {
4445
b.fail( 'should not return NaN' );
4546
}
@@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) {
5859
var z;
5960
var i;
6061

62+
x = uniform( 100, -500.0, 500.0 );
63+
y = uniform( 100, -500.0, 500.0 );
64+
6165
b.tic();
6266
for ( i = 0; i < b.iterations; i++ ) {
63-
x = ( randu()*1000.0 ) - 500.0;
64-
y = ( randu()*1000.0 ) - 500.0;
65-
z = Math.max( Math.abs( x ), Math.abs( y ) ); // eslint-disable-line stdlib/no-builtin-math
67+
z = Math.max( Math.abs( x[ i%x.length ] ), Math.abs( y[ i%y.length ] ) ); // eslint-disable-line stdlib/no-builtin-math
6668
if ( isnan( z ) ) {
6769
b.fail( 'should not return NaN' );
6870
}

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

+5-4
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;
@@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var z;
4545
var i;
4646

47+
x = uniform( 100, -500.0, 500.0 );
48+
y = uniform( 100, -500.0, 500.0 );
49+
4750
b.tic();
4851
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*1000.0 ) - 500.0;
50-
y = ( randu()*1000.0 ) - 500.0;
51-
z = maxabs( x, y );
52+
z = maxabs( x[ i%x.length ], y[ i%y.length ] );
5253
if ( isnan( z ) ) {
5354
b.fail( 'should not return NaN' );
5455
}

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
94-
double y;
93+
double x[ 100 ];
94+
double y[ 100 ];
9595
double z;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
101+
y[ i ] = ( 1000.0*rand_double() ) - 500.0;
102+
}
103+
99104
t = tic();
100105
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 1000.0*rand_double() ) - 500.0;
102-
y = ( 1000.0*rand_double() ) - 500.0;
103-
z = fmax( fabs(x), fabs(y) );
106+
z = fmax( fabs( x[ i%100 ] ), fabs( y[ i%100 ] ) );
104107
if ( z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ static double rand_double( void ) {
9292
static double benchmark( void ) {
9393
double elapsed;
9494
double t;
95-
double x;
96-
double y;
95+
double x[ 100 ];
96+
double y[ 100 ];
9797
double z;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
102+
y[ i ] = ( 1000.0*rand_double() ) - 500.0;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 1000.0*rand_double() ) - 500.0;
103-
y = ( 1000.0*rand_double() ) - 500.0;
104-
z = stdlib_base_maxabs( x, y );
107+
z = stdlib_base_maxabs( x[ i%100 ], y[ i%100 ] );
105108
if ( z != z ) {
106109
printf( "should not return NaN\n" );
107110
break;

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

+3-3
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var maxabsf = require( './../lib' );
@@ -35,8 +35,8 @@ bench( pkg, function benchmark( b ) {
3535
var z;
3636
var i;
3737

38-
x = randu( 100, -500.0, 500.0 );
39-
y = randu( 100, -500.0, 500.0 );
38+
x = uniform( 100, -500.0, 500.0 );
39+
y = uniform( 100, -500.0, 500.0 );
4040

4141
b.tic();
4242
for ( i = 0; i < b.iterations; i++ ) {

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

+3-3
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -44,8 +44,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var z;
4545
var i;
4646

47-
x = randu( 100, -500.0, 500.0 );
48-
y = randu( 100, -500.0, 500.0 );
47+
x = uniform( 100, -500.0, 500.0 );
48+
y = uniform( 100, -500.0, 500.0 );
4949

5050
b.tic();
5151
for ( i = 0; i < b.iterations; i++ ) {

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

+9-7
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 maxabsn = require( './../lib' );
@@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
3535
var z;
3636
var i;
3737

38+
x = uniform( 100, -500.0, 500.0 );
39+
y = uniform( 100, -500.0, 500.0 );
40+
3841
b.tic();
3942
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*1000.0 ) - 500.0;
41-
y = ( randu()*1000.0 ) - 500.0;
42-
z = maxabsn( x, y );
43+
z = maxabsn( x[ i%x.length ], y[ i%y.length ] );
4344
if ( isnan( z ) ) {
4445
b.fail( 'should not return NaN' );
4546
}
@@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) {
5859
var z;
5960
var i;
6061

62+
x = uniform( 100, -500.0, 500.0 );
63+
y = uniform( 100, -500.0, 500.0 );
64+
6165
b.tic();
6266
for ( i = 0; i < b.iterations; i++ ) {
63-
x = ( randu()*1000.0 ) - 500.0;
64-
y = ( randu()*1000.0 ) - 500.0;
65-
z = Math.max( Math.abs( x ), Math.abs( y ) ); // eslint-disable-line stdlib/no-builtin-math
67+
z = Math.max( Math.abs( x[ i%x.length ] ), Math.abs( y[ i%y.length ] ) ); // eslint-disable-line stdlib/no-builtin-math
6668
if ( isnan( z ) ) {
6769
b.fail( 'should not return NaN' );
6870
}

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
94-
double y;
93+
double x[ 100 ];
94+
double y[ 100 ];
9595
double z;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
101+
y[ i ] = ( 1000.0*rand_double() ) - 500.0;
102+
}
103+
99104
t = tic();
100105
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 1000.0*rand_double() ) - 500.0;
102-
y = ( 1000.0*rand_double() ) - 500.0;
103-
z = fmax( fabs(x), fabs(y) );
106+
z = fmax( fabs( x[ i%100 ] ), fabs( y[ i%100 ] ) );
104107
if ( z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

0 commit comments

Comments
 (0)