Skip to content

Commit

Permalink
bench: update random value generation
Browse files Browse the repository at this point in the history
PR-URL: #5404
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
anandkaranubc and kgryte authored Feb 25, 2025
1 parent 3033968 commit 1de4fb4
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 122 deletions.
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 vercos = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = vercos( x );
y = vercos( 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, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 20.0 ) - 10.0;
y = vercos( x );
y = vercos( 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 @@ -89,16 +89,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 ] = ( 20.0*rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0*rand_double() ) - 10.0;
y = 1.0 + cos( x );
y = 1.0 + cos( 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 ] = ( 20.0 * rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0 * rand_double() ) - 10.0;
y = stdlib_base_vercos( x );
y = stdlib_base_vercos( 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 @@ -199,18 +199,18 @@ tape( 'the function computes the versed cosine (for x >= 2**60 (PI/2) )', functi

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

tape( 'the function returns `NaN` if provided `+infinity`', function test( t ) {
var v = vercos( PINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
var v = vercos( NINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
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 versin = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = versin( x );
y = versin( 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, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 20.0 ) - 10.0;
y = versin( x );
y = versin( 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 @@ -89,16 +89,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 ] = ( 20.0*rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0*rand_double() ) - 10.0;
y = 1.0 - cos( x );
y = 1.0 - cos( 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 ] = ( 20.0 * rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0 * rand_double() ) - 10.0;
y = stdlib_base_versin( x );
y = stdlib_base_versin( 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 @@ -199,18 +199,18 @@ tape( 'the function computes the versed sine (for x >= 2**60 (PI/2) )', function

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

tape( 'the function returns `NaN` if provided `+infinity`', function test( t ) {
var v = versin( PINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
var v = versin( NINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
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 wrap = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = wrap( x, -5.0, 5.0 );
y = wrap( x[ i % x.length ], -5.0, 5.0 );
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, -10.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = wrap( x, -5.0, 5.0 );
y = wrap( x[ i % x.length ], -5.0, 5.0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ double wrap( double v, double min, double max ) {
* @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 ] = ( 20.0*rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0*rand_double() ) - 10.0;
y = wrap( x, -5.0, 5.0 );
y = wrap( x[ i%100 ], -5.0, 5.0 );
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 ] = ( 20.0*rand_double() ) - 10.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 20.0*rand_double() ) - 10.0;
y = stdlib_base_wrap( x, -5.0, 5.0 );
y = stdlib_base_wrap( x[ i%100 ], -5.0, 5.0 );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
14 changes: 7 additions & 7 deletions lib/node_modules/@stdlib/math/base/special/wrap/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', function
var v;

v = wrap( NaN, 0.0, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 0.0, NaN, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 3.14, 0.0, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, NaN, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, 0.0, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 3.14, NaN, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, NaN, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ tape( 'if provided `NaN` for any argument, the function returns `NaN`', opts, fu
var v;

v = wrap( NaN, 0.0, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 0.0, NaN, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 3.14, 0.0, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, NaN, 5.0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, 0.0, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( 3.14, NaN, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = wrap( NaN, NaN, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand Down
Loading

1 comment on commit 1de4fb4

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/vercos $\color{green}164/164$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}164/164$
$\color{green}+100.00\%$
math/base/special/versin $\color{green}164/164$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}164/164$
$\color{green}+100.00\%$
math/base/special/wrap $\color{green}236/236$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}236/236$
$\color{green}+100.00\%$
math/base/special/xlog1py $\color{green}190/190$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}190/190$
$\color{green}+100.00\%$
math/base/special/xlogy $\color{green}184/184$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}184/184$
$\color{green}+100.00\%$
math/base/special/xlogyf $\color{green}184/184$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}184/184$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.