Skip to content

Commit d20e133

Browse files
hrshyakgryte
andauthored
bench: update random value generation
PR-URL: #6231 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Harsh <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent dfb9b3f commit d20e133

File tree

11 files changed

+102
-80
lines changed

11 files changed

+102
-80
lines changed

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

Lines changed: 9 additions & 7 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 max = 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 = max( x, y );
43+
z = max( 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( x, y ); // eslint-disable-line stdlib/no-builtin-math
67+
z = Math.max( x[ i%x.length ], 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/max/benchmark/benchmark.native.js

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

47+
x = uniform( 100, -100.0, 100.0 );
48+
y = uniform( 100, -100.0, 100.0 );
49+
4750
b.tic();
4851
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*200.0 ) - 100.0;
50-
y = ( randu()*200.0 ) - 100.0;
51-
z = max( x, y );
52+
z = max( 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/max/benchmark/c/benchmark.c

Lines changed: 8 additions & 5 deletions
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( x, y );
106+
z = fmax( x[ i % 100 ], y[ i % 100 ] );
104107
if ( z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94+
double x[ 100 ];
95+
double y[ 100 ];
9496
double t;
95-
double x;
96-
double y;
9797
double z;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 200.0*rand_double() ) - 100.0;
102+
y[ i ] = ( 200.0*rand_double() ) - 100.0;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 200.0*rand_double() ) - 100.0;
103-
y = ( 200.0*rand_double() ) - 100.0;
104-
z = stdlib_base_max( x, y );
107+
z = stdlib_base_max( 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/max/test/test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
4040
var v;
4141

4242
v = max( NaN, 3.14 );
43-
t.strictEqual( isnan( v ), true, 'returns NaN' );
43+
t.strictEqual( isnan( v ), true, 'returns expected value' );
4444

4545
v = max( 3.14, NaN );
46-
t.strictEqual( isnan( v ), true, 'returns NaN' );
46+
t.strictEqual( isnan( v ), true, 'returns expected value' );
4747

4848
t.end();
4949
});
@@ -52,10 +52,10 @@ tape( 'the function returns `+Infinity` if provided `+Infinity`', function test(
5252
var v;
5353

5454
v = max( PINF, 3.14 );
55-
t.strictEqual( v, PINF, 'returns +infinity' );
55+
t.strictEqual( v, PINF, 'returns expected value' );
5656

5757
v = max( 3.14, PINF );
58-
t.strictEqual( v, PINF, 'returns +infinity' );
58+
t.strictEqual( v, PINF, 'returns expected value' );
5959

6060
t.end();
6161
});
@@ -64,16 +64,16 @@ tape( 'the function returns a correctly signed zero', function test( t ) {
6464
var v;
6565

6666
v = max( +0.0, -0.0 );
67-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
67+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
6868

6969
v = max( -0.0, +0.0 );
70-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
70+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
7171

7272
v = max( -0.0, -0.0 );
73-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
73+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
7474

7575
v = max( +0.0, +0.0 );
76-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
76+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
7777

7878
t.end();
7979
});
@@ -82,10 +82,10 @@ tape( 'the function returns the maximum value', function test( t ) {
8282
var v;
8383

8484
v = max( 4.2, 3.14 );
85-
t.strictEqual( v, 4.2, 'returns max value' );
85+
t.strictEqual( v, 4.2, 'returns expected value' );
8686

8787
v = max( -4.2, 3.14 );
88-
t.strictEqual( v, 3.14, 'returns max value' );
88+
t.strictEqual( v, 3.14, 'returns expected value' );
8989

9090
t.end();
9191
});

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t )
4949
var v;
5050

5151
v = max( NaN, 3.14 );
52-
t.strictEqual( isnan( v ), true, 'returns NaN' );
52+
t.strictEqual( isnan( v ), true, 'returns expected value' );
5353

5454
v = max( 3.14, NaN );
55-
t.strictEqual( isnan( v ), true, 'returns NaN' );
55+
t.strictEqual( isnan( v ), true, 'returns expected value' );
5656

5757
t.end();
5858
});
@@ -61,10 +61,10 @@ tape( 'the function returns `Infinity` if provided `Infinity`', opts, function t
6161
var v;
6262

6363
v = max( PINF, 3.14 );
64-
t.strictEqual( v, PINF, 'returns infinity' );
64+
t.strictEqual( v, PINF, 'returns expected value' );
6565

6666
v = max( 3.14, PINF );
67-
t.strictEqual( v, PINF, 'returns infinity' );
67+
t.strictEqual( v, PINF, 'returns expected value' );
6868

6969
t.end();
7070
});
@@ -73,16 +73,16 @@ tape( 'the function returns a correctly signed zero', opts, function test( t ) {
7373
var v;
7474

7575
v = max( +0.0, -0.0 );
76-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
76+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
7777

7878
v = max( -0.0, +0.0 );
79-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
79+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
8080

8181
v = max( -0.0, -0.0 );
82-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
82+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
8383

8484
v = max( +0.0, +0.0 );
85-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
85+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
8686

8787
t.end();
8888
});
@@ -91,10 +91,10 @@ tape( 'the function returns the maximum value', opts, function test( t ) {
9191
var v;
9292

9393
v = max( 4.2, 3.14 );
94-
t.strictEqual( v, 4.2, 'returns max value' );
94+
t.strictEqual( v, 4.2, 'returns expected value' );
9595

9696
v = max( -4.2, 3.14 );
97-
t.strictEqual( v, 3.14, 'returns max value' );
97+
t.strictEqual( v, 3.14, 'returns expected value' );
9898

9999
t.end();
100100
});

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

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

38-
x = randu( 100, -100.0, 100.0 );
39-
y = randu( 100, -100.0, 100.0 );
38+
x = uniform( 100, -100.0, 100.0, {
39+
'dtype': 'float32'
40+
});
41+
y = uniform( 100, -100.0, 100.0, {
42+
'dtype': 'float32'
43+
});
4044

4145
b.tic();
4246
for ( i = 0; i < b.iterations; i++ ) {

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

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

47-
x = randu( 100, -100.0, 100.0 );
48-
y = randu( 100, -100.0, 100.0 );
47+
x = uniform( 100, -100.0, 100.0, {
48+
'dtype': 'float32'
49+
});
50+
y = uniform( 100, -100.0, 100.0, {
51+
'dtype': 'float32'
52+
});
4953

5054
b.tic();
5155
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 9 additions & 7 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 maxn = 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 = maxn( x, y );
43+
z = maxn( 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( x, y ); // eslint-disable-line stdlib/no-builtin-math
67+
z = Math.max( x[ i % x.length ], 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/maxn/benchmark/c/benchmark.c

Lines changed: 8 additions & 5 deletions
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( x, y );
106+
z = fmax( x[ i % 100 ], y[ i % 100 ] );
104107
if ( z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

0 commit comments

Comments
 (0)