Skip to content

Commit 5b45d4b

Browse files
authored
bench: update random value generation
PR-URL: #6288 Reviewed-by: Athan Reines <[email protected]>
1 parent 9ce2dec commit 5b45d4b

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

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

Lines changed: 7 additions & 5 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 sin = require( '@stdlib/math/base/special/sin' );
2727
var pkg = require( './../package.json' ).name;
@@ -35,10 +35,11 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38+
x = uniform( 100, -10.0, 10.0 );
39+
3840
b.tic();
3941
for ( i = 0; i < b.iterations; i++ ) {
40-
x = (randu() * 20.0) - 10.0;
41-
y = csc( x );
42+
y = csc( x[ i%x.length ] );
4243
if ( isnan( y ) ) {
4344
b.fail( 'should not return NaN' );
4445
}
@@ -56,10 +57,11 @@ bench( pkg + '::built-in', function benchmark( b ) {
5657
var y;
5758
var i;
5859

60+
x = uniform( 100, -10.0, 10.0 );
61+
5962
b.tic();
6063
for ( i = 0; i < b.iterations; i++ ) {
61-
x = (randu() * 20.0) - 10.0;
62-
y = 1.0 / sin( x );
64+
y = 1.0 / sin( x[ i%x.length ] );
6365
if ( isnan( y ) ) {
6466
b.fail( 'should not return NaN' );
6567
}

lib/node_modules/@stdlib/math/base/special/csc/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 = csc( x );
50+
y = csc( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

lib/node_modules/@stdlib/math/base/special/csc/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_csc( x );
105+
y = stdlib_base_csc( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,18 @@ tape( 'if provided a multiple of `pi`, the function does not return `~-infinity`
379379

380380
tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) {
381381
var v = csc(NaN);
382-
t.equal(isnan(v), true, 'returns NaN');
382+
t.equal(isnan(v), true, 'returns expected value');
383383
t.end();
384384
});
385385

386386
tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) {
387387
var v = csc(PINF);
388-
t.equal(isnan(v), true, 'returns NaN');
388+
t.equal(isnan(v), true, 'returns expected value');
389389
t.end();
390390
});
391391

392392
tape( 'if provided `-infinity`, the function returns `NaN`', function test( t ) {
393393
var v = csc(NINF);
394-
t.equal(isnan(v), true, 'returns NaN');
394+
t.equal(isnan(v), true, 'returns expected value');
395395
t.end();
396396
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,18 @@ tape( 'if provided a multiple of `pi`, the function does not return `~-infinity`
388388

389389
tape( 'if provided a `NaN`, the function returns `expected value`', opts, function test( t ) {
390390
var v = csc(NaN);
391-
t.equal(isnan(v), true, 'returns NaN');
391+
t.equal(isnan(v), true, 'returns expected value');
392392
t.end();
393393
});
394394

395395
tape( 'if provided `+infinity`, the function returns `expected value`', opts, function test( t ) {
396396
var v = csc(PINF);
397-
t.equal(isnan(v), true, 'returns NaN');
397+
t.equal(isnan(v), true, 'returns expected value');
398398
t.end();
399399
});
400400

401401
tape( 'if provided `-infinity`, the function returns `expected value`', opts, function test( t ) {
402402
var v = csc(NINF);
403-
t.equal(isnan(v), true, 'returns NaN');
403+
t.equal(isnan(v), true, 'returns expected value');
404404
t.end();
405405
});

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

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

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

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

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

Lines changed: 2 additions & 2 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 csch = require( './../lib' );
@@ -34,7 +34,7 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = randu( 100, -5.0, 5.0 );
37+
x = uniform( 100, -5.0, 5.0 );
3838

3939
b.tic();
4040
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/math/base/special/csch/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, -5.0, 5.0 );
46+
x = uniform( 100, -5.0, 5.0 );
4747

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

0 commit comments

Comments
 (0)