Skip to content

Commit 52c0299

Browse files
bench: refactor random number generation
PR-URL: #5397 Reviewed-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 18ad933 commit 52c0299

File tree

27 files changed

+132
-84
lines changed

27 files changed

+132
-84
lines changed

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

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,19 @@ static double rand_double( void ) {
100100
* @return elapsed time in seconds
101101
*/
102102
static double benchmark( void ) {
103+
double x[ 100 ];
103104
double elapsed;
104-
double x;
105105
double y;
106106
double t;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = rand_double() * 100000.0;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = rand_double() * 100000.0;
112-
y = j0( x );
115+
y = j0( x[ i%100 ] );
113116
if ( y != y ) {
114117
printf( "should not return NaN\n" );
115118
break;

lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/cephes/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ static double rand_double( void ) {
9494
* @return elapsed time in seconds
9595
*/
9696
static double benchmark( void ) {
97+
double x[ 100 ];
9798
double elapsed;
98-
double x;
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = rand_double() * 100000.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = rand_double() * 100000.0;
106-
y = j0( x );
109+
y = j0( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ tape( 'the function is an even function (f(x) = f(-x))', function test( t ) {
319319

320320
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
321321
var v = j0( NaN );
322-
t.equal( isnan( v ), true, 'returns NaN' );
322+
t.equal( isnan( v ), true, 'returns expected value' );
323323
t.end();
324324
});
325325

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

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,19 @@ static double rand_double( void ) {
100100
* @return elapsed time in seconds
101101
*/
102102
static double benchmark( void ) {
103+
double x[ 100 ];
103104
double elapsed;
104-
double x;
105105
double y;
106106
double t;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = rand_double() * 100000.0;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = rand_double() * 100000.0;
112-
y = j1( x );
115+
y = j1( x[ i%100 ] );
113116
if ( y != y ) {
114117
printf( "should not return NaN\n" );
115118
break;

lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/cephes/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ static double rand_double( void ) {
9494
* @return elapsed time in seconds
9595
*/
9696
static double benchmark( void ) {
97+
double x[ 100 ];
9798
double elapsed;
98-
double x;
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = rand_double() * 100000.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = rand_double() * 100000.0;
106-
y = j1( x );
109+
y = j1( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ tape( 'the function is an odd function (f(x) = -f(-x))', function test( t ) {
319319

320320
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
321321
var v = j1( NaN );
322-
t.equal( isnan( v ), true, 'returns NaN' );
322+
t.equal( isnan( v ), true, 'returns expected value' );
323323
t.end();
324324
});
325325

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

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,19 @@ static double rand_double( void ) {
100100
* @return elapsed time in seconds
101101
*/
102102
static double benchmark( void ) {
103+
double x[ 100 ];
103104
double elapsed;
104-
double x;
105105
double y;
106106
double t;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = rand_double() * 100000.0;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = rand_double() * 100000.0;
112-
y = y0( x );
115+
y = y0( x[ i%100 ] );
113116
if ( y != y ) {
114117
printf( "should not return NaN\n" );
115118
break;

lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/cephes/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ static double rand_double( void ) {
9494
* @return elapsed time in seconds
9595
*/
9696
static double benchmark( void ) {
97+
double x[ 100 ];
9798
double elapsed;
98-
double x;
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = rand_double() * 100000.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = rand_double() * 100000.0;
106-
y = y0( x );
109+
y = y0( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ tape( 'the function returns `NaN` for negative numbers', function test( t ) {
266266
for ( i = 0; i < 1000; i++ ) {
267267
x = -( randu() * 100.0 ) - EPS;
268268
v = y0( x );
269-
t.equal( isnan( v ), true, 'returns NaN' );
269+
t.equal( isnan( v ), true, 'returns expected value' );
270270
}
271271
t.end();
272272
});
@@ -279,7 +279,7 @@ tape( 'the function returns `-Infintiy` if provided `0.0`', function test( t ) {
279279

280280
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
281281
var v = y0( NaN );
282-
t.equal( isnan( v ), true, 'returns NaN' );
282+
t.equal( isnan( v ), true, 'returns expected value' );
283283
t.end();
284284
});
285285

@@ -291,6 +291,6 @@ tape( 'the function returns `0.0` if provided `+infinity`', function test( t ) {
291291

292292
tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
293293
var v = y0( NINF );
294-
t.equal( isnan( v ), true, 'returns NaN' );
294+
t.equal( isnan( v ), true, 'returns expected value' );
295295
t.end();
296296
});

0 commit comments

Comments
 (0)