Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: refactor random number generation #5397

Merged
merged 3 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var j0 = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100000.0 ) - 0.0;
y = j0( x );
y = j0( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 100000.0 ) - 0.0;
y = j0( x );
y = j0( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = j0( x );
y = j0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = j0( x );
y = j0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = 100000.0 * rand_double();
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100000.0 * rand_double() ) - 0.0;
y = stdlib_base_besselj0( x );
y = stdlib_base_besselj0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ tape( 'the function is an even function (f(x) = f(-x))', function test( t ) {

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = j0( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var j1 = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100000.0 ) - 0.0;
y = j1( x );
y = j1( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 100000.0 ) - 0.0;
y = j1( x );
y = j1( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = j1( x );
y = j1( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = j1( x );
y = j1( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = 100000.0 * rand_double();
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100000.0 * rand_double() ) - 0.0;
y = stdlib_base_besselj1( x );
y = stdlib_base_besselj1( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ tape( 'the function is an odd function (f(x) = -f(-x))', function test( t ) {

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = j1( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var y0 = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100000.0 ) - 0.0;
y = y0( x );
y = y0( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 0.0, 100000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 100000.0 ) - 0.0;
y = y0( x );
y = y0( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = y0( x );
y = y0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_double() * 100000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = rand_double() * 100000.0;
y = y0( x );
y = y0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = 100000.0 * rand_double();
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100000.0 * rand_double() ) - 0.0;
y = stdlib_base_bessely0( x );
y = stdlib_base_bessely0( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ tape( 'the function returns `NaN` for negative numbers', function test( t ) {
for ( i = 0; i < 1000; i++ ) {
x = -( randu() * 100.0 ) - EPS;
v = y0( x );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -279,7 +279,7 @@ tape( 'the function returns `-Infintiy` if provided `0.0`', function test( t ) {

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = y0( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

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

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