Skip to content

Commit cbceb64

Browse files
authored
bench: update random value generation
PR-URL: #6267 Reviewed-by: Athan Reines <[email protected]>
1 parent 60310a4 commit cbceb64

File tree

15 files changed

+69
-45
lines changed

15 files changed

+69
-45
lines changed

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

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

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

lib/node_modules/@stdlib/math/base/special/hacovercos/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 ] = ( 20.0*rand_double() ) - 10.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 20.0*rand_double() ) - 10.0;
101-
y = ( 1.0 + sin( x ) ) / 2.0;
104+
y = ( 1.0 + sin( x[ i%100 ] ) ) / 2.0;
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,18 @@ tape( 'the function computes the half-value coversed cosine (for x >= 2**60 (PI/
193193

194194
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
195195
var v = hacovercos( NaN );
196-
t.equal( isnan( v ), true, 'returns NaN' );
196+
t.equal( isnan( v ), true, 'returns expected value' );
197197
t.end();
198198
});
199199

200200
tape( 'the function returns `NaN` if provided `+infinity`', function test( t ) {
201201
var v = hacovercos( PINF );
202-
t.equal( isnan( v ), true, 'returns NaN' );
202+
t.equal( isnan( v ), true, 'returns expected value' );
203203
t.end();
204204
});
205205

206206
tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
207207
var v = hacovercos( NINF );
208-
t.equal( isnan( v ), true, 'returns NaN' );
208+
t.equal( isnan( v ), true, 'returns expected value' );
209209
t.end();
210210
});

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

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

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

lib/node_modules/@stdlib/math/base/special/hacoversin/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 ] = ( 20.0*rand_double() ) - 10.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 20.0*rand_double() ) - 10.0;
101-
y = ( 1.0 - sin( x ) ) / 2.0;
104+
y = ( 1.0 - sin( x[ i%100 ] ) ) / 2.0;
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,18 @@ tape( 'the function computes the half-value coversed sine (for x >= 2**60 (PI/2)
193193

194194
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
195195
var v = hacoversin( NaN );
196-
t.equal( isnan( v ), true, 'returns NaN' );
196+
t.equal( isnan( v ), true, 'returns expected value' );
197197
t.end();
198198
});
199199

200200
tape( 'the function returns `NaN` if provided `+infinity`', function test( t ) {
201201
var v = hacoversin( PINF );
202-
t.equal( isnan( v ), true, 'returns NaN' );
202+
t.equal( isnan( v ), true, 'returns expected value' );
203203
t.end();
204204
});
205205

206206
tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
207207
var v = hacoversin( NINF );
208-
t.equal( isnan( v ), true, 'returns NaN' );
208+
t.equal( isnan( v ), true, 'returns expected value' );
209209
t.end();
210210
});

0 commit comments

Comments
 (0)