Skip to content

bench: update random value generation #6393

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

Merged
merged 1 commit into from
Apr 2, 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var pdifff = require( './../lib' );
Expand All @@ -35,11 +35,16 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -500.0, 500.0, {
'dtype': 'float32'
});
y = uniform( 100, -500.0, 500.0, {
'dtype': 'float32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = pdifff( x, y );
z = pdifff( x[ i%x.length ], y[ i%y.length ] );
if ( isnanf( z ) ) {
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -44,11 +44,16 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -500.0, 500.0, {
'dtype': 'float32'
});
y = uniform( 100, -500.0, 500.0, {
'dtype': 'float32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = pdifff( x, y );
z = pdifff( x[ i%x.length ], y[ i%y.length ] );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ float pdifff( float x, float y ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float y;
float x[ 100 ];
float y[ 100 ];
float z;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
y[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = ( 1000.0f*rand_float() ) - 500.0f;
z = pdifff( x, y );
z = pdifff( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ static float rand_float( void ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float y;
float x[ 100 ];
float y[ 100 ];
float z;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
y[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = ( 1000.0f*rand_float() ) - 500.0f;
z = stdlib_base_pdifff( x, y );
z = stdlib_base_pdifff( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
32 changes: 16 additions & 16 deletions lib/node_modules/@stdlib/math/base/special/pdifff/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var v;

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

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

v = pdifff( NaN, NaN );
t.strictEqual( isnanf( v ), true, 'returns NaN' );
t.strictEqual( isnanf( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -56,40 +56,40 @@ tape( 'the function returns `+infinity` if the first argument is `+infinity`', f
var v;

v = pdifff( PINF, 3.14 );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

v = pdifff( PINF, NINF );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

t.end();
});

tape( 'the function returns `0` if both arguments are `+infinity`', function test( t ) {
var v = pdifff( PINF, PINF );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if the difference between the first and second arguments is less than or equal to `0`', function test( t ) {
var v;

v = pdifff( +0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( -0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( -0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( +0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( 3.14, 3.14 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( 3.14, 4.2 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -98,13 +98,13 @@ tape( 'the function returns the positive difference between `x` and `y`', functi
var v;

v = pdifff( 4.15, 3.15 );
t.strictEqual( v, 1.0, 'returns the positive difference' );
t.strictEqual( v, 1.0, 'returns expected value' );

v = pdifff( -4.2, 3.14 );
t.strictEqual( v, 0.0, 'returns the positive difference' );
t.strictEqual( v, 0.0, 'returns expected value' );

v = pdifff( -4.2, -5.2 );
t.strictEqual( v, 1.0, 'returns the positive difference' );
t.strictEqual( v, 1.0, 'returns expected value' );

t.end();
});
Expand All @@ -115,7 +115,7 @@ tape( 'the function returns `+infinity` if overflow occurs', function test( t )

half = FLOAT32_MAX / 2.0;
v = pdifff( half, -(half*1.5) );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t )
var v;

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

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

v = pdifff( NaN, NaN );
t.strictEqual( isnanf( v ), true, 'returns NaN' );
t.strictEqual( isnanf( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -65,40 +65,40 @@ tape( 'the function returns `+infinity` if the first argument is `+infinity`', o
var v;

v = pdifff( PINF, 3.14 );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

v = pdifff( PINF, NINF );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

t.end();
});

tape( 'the function returns `0` if both arguments are `+infinity`', opts, function test( t ) {
var v = pdifff( PINF, PINF );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if the difference between the first and second arguments is less than or equal to `0`', opts, function test( t ) {
var v;

v = pdifff( +0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( -0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( -0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( +0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( 3.14, 3.14 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = pdifff( 3.14, 4.2 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -107,13 +107,13 @@ tape( 'the function returns the positive difference between `x` and `y`', opts,
var v;

v = pdifff( 4.15, 3.15 );
t.strictEqual( v, 1.0, 'returns the positive difference' );
t.strictEqual( v, 1.0, 'returns expected value' );

v = pdifff( -4.2, 3.14 );
t.strictEqual( v, 0.0, 'returns the positive difference' );
t.strictEqual( v, 0.0, 'returns expected value' );

v = pdifff( -4.2, -5.2 );
t.strictEqual( v, 1.0, 'returns the positive difference' );
t.strictEqual( v, 1.0, 'returns expected value' );

t.end();
});
Expand All @@ -124,7 +124,7 @@ tape( 'the function returns `+infinity` if overflow occurs', opts, function test

half = FLOAT32_MAX / 2.0;
v = pdifff( half, -(half*1.5) );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, '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 pow = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 100.0 );
y = uniform( 100, -50.0, 50.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 0.0;
y = ( randu()*100.0 ) - 50.0;
z = pow( x, y );
z = pow( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 100.0 );
y = uniform( 100, -50.0, 50.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 0.0;
y = ( randu()*100.0 ) - 50.0;
z = Math.pow( x, y ); // eslint-disable-line stdlib/no-builtin-math
z = Math.pow( x[ i%x.length ], y[ i%y.length ] ); // eslint-disable-line stdlib/no-builtin-math
if ( isnan( z ) ) {
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 @@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

v = uniform( 100, 0.0, 10.0 );
x = uniform( 100, -5.0, 5.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = ( randu()*10.0 );
x = ( randu()*10.0 ) - 5.0;
y = pow( v, x );
y = pow( v[ i%v.length ], 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 @@ -90,17 +90,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) - 0.0;
y[ i ] = ( 100.0*rand_double() ) - 50.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) - 0.0;
y = ( 100.0*rand_double() ) - 50.0;
z = pow( x, y );
z = pow( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
Loading
Loading