Skip to content

Commit 8d343e1

Browse files
authored
bench: update random value generation
PR-URL: #6398 Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Harsh <[email protected]>
1 parent 7347f29 commit 8d343e1

File tree

24 files changed

+128
-86
lines changed

24 files changed

+128
-86
lines changed

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

Lines changed: 6 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var TWO_PI = require( '@stdlib/constants/float32/two-pi' );
2727
var pkg = require( './../package.json' ).name;
@@ -35,10 +35,13 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38+
x = uniform( 100, 0.0, TWO_PI, {
39+
'dtype': 'float32'
40+
});
41+
3842
b.tic();
3943
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu() * TWO_PI ) - 0.0;
41-
y = rad2degf( x );
44+
y = rad2degf( x[ i%x.length ] );
4245
if ( isnanf( y ) ) {
4346
b.fail( 'should not return NaN' );
4447
}

lib/node_modules/@stdlib/math/base/special/rad2degf/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 TWO_PI = require( '@stdlib/constants/float32/two-pi' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -44,10 +44,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var y;
4545
var i;
4646

47+
x = uniform( 100, 0.0, TWO_PI, {
48+
'dtype': 'float32'
49+
});
50+
4751
b.tic();
4852
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu() * TWO_PI ) - 0.0;
50-
y = rad2degf( x );
53+
y = rad2degf( x[ i%x.length ] );
5154
if ( isnanf( y ) ) {
5255
b.fail( 'should not return NaN' );
5356
}

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

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

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ tape( 'main export is a function', function test( t ) {
4646

4747
tape( 'if provided `+infinity`, the function returns `+infinity`', function test( t ) {
4848
var r = rad2degf( PINF );
49-
t.equal( r, PINF, 'returns +infinity' );
49+
t.equal( r, PINF, 'returns expected value' );
5050
t.end();
5151
});
5252

5353
tape( 'if provided `-infinity`, the function returns `-infinity`', function test( t ) {
5454
var r = rad2degf( NINF );
55-
t.equal( r, NINF, 'returns -infinity' );
55+
t.equal( r, NINF, 'returns expected value' );
5656
t.end();
5757
});
5858

@@ -160,6 +160,6 @@ tape( 'the function converts an angle from radians to degrees (canonical values)
160160

161161
tape( 'if provided a value greater than `~6e+36`, the function will underflow', function test( t ) {
162162
var r = rad2degf( 6.0e+36 );
163-
t.equal( r, PINF, 'returns +infinity' );
163+
t.equal( r, PINF, 'returns expected value' );
164164
t.end();
165165
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ tape( 'main export is a function', opts, function test( t ) {
5555

5656
tape( 'if provided `+infinity`, the function returns `+infinity`', opts, function test( t ) {
5757
var r = rad2degf( PINF );
58-
t.equal( r, PINF, 'returns +infinity' );
58+
t.equal( r, PINF, 'returns expected value' );
5959
t.end();
6060
});
6161

6262
tape( 'if provided `-infinity`, the function returns `-infinity`', opts, function test( t ) {
6363
var r = rad2degf( NINF );
64-
t.equal( r, NINF, 'returns -infinity' );
64+
t.equal( r, NINF, 'returns expected value' );
6565
t.end();
6666
});
6767

@@ -169,6 +169,6 @@ tape( 'the function converts an angle from radians to degrees (canonical values)
169169

170170
tape( 'if provided a value greater than `~6e+36`, the function will underflow', opts, function test( t ) {
171171
var r = rad2degf( 6.0e+36 );
172-
t.equal( r, PINF, 'returns +infinity' );
172+
t.equal( r, PINF, 'returns expected value' );
173173
t.end();
174174
});

lib/node_modules/@stdlib/math/base/special/ramp/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 ramp = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ double ramp( double x ) {
103103
*/
104104
static double benchmark( void ) {
105105
double elapsed;
106-
double x;
106+
double x[ 100 ];
107107
double y;
108108
double t;
109109
int i;
110110

111+
for ( i = 0; i < 100; i++ ) {
112+
x[ i ] = ( 100.0*rand_double() ) - 50.0;
113+
}
114+
111115
t = tic();
112116
for ( i = 0; i < ITERATIONS; i++ ) {
113-
x = ( 100.0*rand_double() ) - 50.0;
114-
y = ramp( x );
117+
y = ramp( x[ i%100 ] );
115118
if ( y != y ) {
116119
printf( "should not return NaN\n" );
117120
break;

lib/node_modules/@stdlib/math/base/special/ramp/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 ] = ( 100.0*rand_double() ) - 50.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 100.0*rand_double() ) - 50.0;
102-
y = stdlib_base_ramp( x );
105+
y = stdlib_base_ramp( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tape( 'the function returns `0` if `x` is less than `0`', function test( t ) {
4646
for ( i = 0; i < 1e3; i++ ) {
4747
x = -( randu()*100.0 ) - EPS;
4848
v = ramp( x );
49-
t.equal( isPositiveZero( v ), true, 'returns 0 when provided '+x );
49+
t.equal( isPositiveZero( v ), true, 'returns expected value when provided '+x );
5050
}
5151
t.end();
5252
});
@@ -66,24 +66,24 @@ tape( 'the function returns `x` if `x` is nonnegative', function test( t ) {
6666

6767
tape( 'the function returns `0` if provided `-0`', function test( t ) {
6868
var v = ramp( -0.0 );
69-
t.equal( isPositiveZero( v ), true, 'returns +0' );
69+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
7070
t.end();
7171
});
7272

7373
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
7474
var v = ramp( NaN );
75-
t.equal( isnan( v ), true, 'returns NaN' );
75+
t.equal( isnan( v ), true, 'returns expected value' );
7676
t.end();
7777
});
7878

7979
tape( 'the function returns `0` if provided `-infinity`', function test( t ) {
8080
var v = ramp( NINF );
81-
t.equal( v, 0.0, 'returns 0' );
81+
t.equal( v, 0.0, 'returns expected value' );
8282
t.end();
8383
});
8484

8585
tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) {
8686
var v = ramp( PINF );
87-
t.equal( v, PINF, 'returns +infinity' );
87+
t.equal( v, PINF, 'returns expected value' );
8888
t.end();
8989
});

0 commit comments

Comments
 (0)