Skip to content

Commit 445050b

Browse files
hrshyaGirish-Garg
authored andcommitted
bench: update random value generation
PR-URL: stdlib-js#6291 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent c837d99 commit 445050b

File tree

14 files changed

+61
-46
lines changed

14 files changed

+61
-46
lines changed

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

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

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

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

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

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

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

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

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

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

4646
tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) {
4747
var v = cotd( NaN );
48-
t.equal( isnan( v ), true, 'returns NaN' );
48+
t.equal( isnan( v ), true, 'returns expected value' );
4949
t.end();
5050
});
5151

@@ -107,13 +107,13 @@ tape( 'the function computes the cotangent of an angle measured in degrees (posi
107107

108108
tape( 'if provided `+Infinity`, the function returns `NaN`', function test( t ) {
109109
var v = cotd( PINF );
110-
t.equal( isnan( v ), true, 'returns NaN' );
110+
t.equal( isnan( v ), true, 'returns expected value' );
111111
t.end();
112112
});
113113

114114
tape( 'if provided `-Infinity`, the function returns `NaN`', function test( t ) {
115115
var v = cotd( NINF );
116-
t.equal( isnan( v ), true, 'returns NaN' );
116+
t.equal( isnan( v ), true, 'returns expected value' );
117117
t.end();
118118
});
119119

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

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

5555
tape( 'if provided a `NaN`, the function returns `NaN`', opts, function test( t ) {
5656
var v = cotd( NaN );
57-
t.equal( isnan( v ), true, 'returns NaN' );
57+
t.equal( isnan( v ), true, 'returns expected value' );
5858
t.end();
5959
});
6060

@@ -116,13 +116,13 @@ tape( 'the function computes the cotangent of an angle measured in degrees (posi
116116

117117
tape( 'if provided `+Infinity`, the function returns `NaN`', opts, function test( t ) {
118118
var v = cotd( PINF );
119-
t.equal( isnan( v ), true, 'returns NaN' );
119+
t.equal( isnan( v ), true, 'returns expected value' );
120120
t.end();
121121
});
122122

123123
tape( 'if provided `-Infinity`, the function returns `NaN`', opts, function test( t ) {
124124
var v = cotd( NINF );
125-
t.equal( isnan( v ), true, 'returns NaN' );
125+
t.equal( isnan( v ), true, 'returns expected value' );
126126
t.end();
127127
});
128128

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

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

0 commit comments

Comments
 (0)