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: update random value generation #6301

Merged
merged 2 commits into from
Mar 22, 2025
Merged
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
@@ -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 copysign = require( './../lib' );
@@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -5.0e6, 5.0e6 );
y = uniform( 100, -5.0e6, 5.0e6 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = ( randu()*1.0e7 ) - 5.0e6;
z = copysign( x, y );
z = copysign( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Original file line number Diff line number Diff line change
@@ -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;
@@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -5.0e6, 5.0e6 );
y = uniform( 100, -5.0e6, 5.0e6 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = ( randu()*1.0e7 ) - 5.0e6;
z = copysign( x, y );
z = copysign( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Original file line number Diff line number Diff line change
@@ -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 ] = ( 1.0e7*rand_double() ) - 5.0e6;
y[ i ] = ( 1.0e7*rand_double() ) - 5.0e6;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1.0e7*rand_double() ) - 5.0e6;
y = ( 1.0e7*rand_double() ) - 5.0e6;
z = copysign( x, y );
z = copysign( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Original file line number Diff line number Diff line change
@@ -91,17 +91,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 ] = ( 1.0e7*rand_double() ) - 5.0e6;
y[ i ] = ( 1.0e7*rand_double() ) - 5.0e6;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1.0e7*rand_double() ) - 5.0e6;
y = ( 1.0e7*rand_double() ) - 5.0e6;
z = stdlib_base_copysign( x, y );
z = stdlib_base_copysign( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
28 changes: 14 additions & 14 deletions lib/node_modules/@stdlib/math/base/special/copysign/test/test.js
Original file line number Diff line number Diff line change
@@ -63,10 +63,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', function test( t ) {
var z;

z = copysign( NaN, -1.0 );
t.equal( isnan( z ), true, 'returns NaN' );
t.equal( isnan( z ), true, 'returns expected value' );

z = copysign( NaN, 1.0 );
t.equal( isnan( z ), true, 'returns NaN' );
t.equal( isnan( z ), true, 'returns expected value' );

t.end();
});
@@ -87,10 +87,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', function
var z;

z = copysign( PINF, -1.0 );
t.equal( z, NINF, 'returns -infinity' );
t.equal( z, NINF, 'returns expected value' );

z = copysign( PINF, 1.0 );
t.equal( z, PINF, 'returns +infinity' );
t.equal( z, PINF, 'returns expected value' );

t.end();
});
@@ -99,10 +99,10 @@ tape( 'if `y` is `+infinity`, the function returns a positive number', function
var z;

z = copysign( -1.0, PINF );
t.equal( z, 1.0, 'returns +1' );
t.equal( z, 1.0, 'returns expected value' );

z = copysign( 1.0, PINF );
t.equal( z, 1.0, 'returns +1' );
t.equal( z, 1.0, 'returns expected value' );

t.end();
});
@@ -111,10 +111,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', function
var z;

z = copysign( NINF, -1.0 );
t.equal( z, NINF, 'returns -infinity' );
t.equal( z, NINF, 'returns expected value' );

z = copysign( NINF, 1.0 );
t.equal( z, PINF, 'returns +infinity' );
t.equal( z, PINF, 'returns expected value' );

t.end();
});
@@ -123,10 +123,10 @@ tape( 'if `y` is `-infinity`, the function returns a negative number', function
var z;

z = copysign( -1.0, NINF );
t.equal( z, -1.0, 'returns -1' );
t.equal( z, -1.0, 'returns expected value' );

z = copysign( 1.0, NINF );
t.equal( z, -1.0, 'returns -1' );
t.equal( z, -1.0, 'returns expected value' );

t.end();
});
@@ -138,10 +138,10 @@ tape( 'the function supports copying a sign from `0`', function test( t ) {
x = 3.14;

z = copysign( x, 0.0 );
t.equal( z, 3.14, 'returns +3.14' );
t.equal( z, 3.14, 'returns expected value' );

z = copysign( x, -0.0 );
t.equal( z, -3.14, 'returns -3.14' );
t.equal( z, -3.14, 'returns expected value' );

t.end();
});
@@ -150,10 +150,10 @@ tape( 'the function supports copying a sign to `0`', function test( t ) {
var z;

z = copysign( -0.0, 1.0 );
t.equal( isPositiveZero( z ), true, 'returns +0' );
t.equal( isPositiveZero( z ), true, 'returns expected value' );

z = copysign( 0.0, -1.0 );
t.equal( isNegativeZero( z ), true, 'returns -0' );
t.equal( isNegativeZero( z ), true, 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
@@ -72,10 +72,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', opts, function test( t ) {
var z;

z = copysign( NaN, -1.0 );
t.equal( isnan( z ), true, 'returns NaN' );
t.equal( isnan( z ), true, 'returns expected value' );

z = copysign( NaN, 1.0 );
t.equal( isnan( z ), true, 'returns NaN' );
t.equal( isnan( z ), true, 'returns expected value' );

t.end();
});
@@ -96,10 +96,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', opts, fu
var z;

z = copysign( PINF, -1.0 );
t.equal( z, NINF, 'returns -infinity' );
t.equal( z, NINF, 'returns expected value' );

z = copysign( PINF, 1.0 );
t.equal( z, PINF, 'returns +infinity' );
t.equal( z, PINF, 'returns expected value' );

t.end();
});
@@ -108,10 +108,10 @@ tape( 'if `y` is `+infinity`, the function returns a positive number', opts, fun
var z;

z = copysign( -1.0, PINF );
t.equal( z, 1.0, 'returns +1' );
t.equal( z, 1.0, 'returns expected value' );

z = copysign( 1.0, PINF );
t.equal( z, 1.0, 'returns +1' );
t.equal( z, 1.0, 'returns expected value' );

t.end();
});
@@ -120,10 +120,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', opts, fu
var z;

z = copysign( NINF, -1.0 );
t.equal( z, NINF, 'returns -infinity' );
t.equal( z, NINF, 'returns expected value' );

z = copysign( NINF, 1.0 );
t.equal( z, PINF, 'returns +infinity' );
t.equal( z, PINF, 'returns expected value' );

t.end();
});
@@ -132,10 +132,10 @@ tape( 'if `y` is `-infinity`, the function returns a negative number', opts, fun
var z;

z = copysign( -1.0, NINF );
t.equal( z, -1.0, 'returns -1' );
t.equal( z, -1.0, 'returns expected value' );

z = copysign( 1.0, NINF );
t.equal( z, -1.0, 'returns -1' );
t.equal( z, -1.0, 'returns expected value' );

t.end();
});
@@ -147,10 +147,10 @@ tape( 'the function supports copying a sign from `0`', opts, function test( t )
x = 3.14;

z = copysign( x, 0.0 );
t.equal( z, 3.14, 'returns +3.14' );
t.equal( z, 3.14, 'returns expected value' );

z = copysign( x, -0.0 );
t.equal( z, -3.14, 'returns -3.14' );
t.equal( z, -3.14, 'returns expected value' );

t.end();
});
@@ -159,10 +159,10 @@ tape( 'the function supports copying a sign to `0`', opts, function test( t ) {
var z;

z = copysign( -0.0, 1.0 );
t.equal( isPositiveZero( z ), true, 'returns +0' );
t.equal( isPositiveZero( z ), true, 'returns expected value' );

z = copysign( 0.0, -1.0 );
t.equal( isNegativeZero( z ), true, 'returns -0' );
t.equal( isNegativeZero( z ), true, 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
@@ -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 copysignf = require( './../lib' );
@@ -35,11 +35,16 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = ( randu()*1.0e7 ) - 5.0e6;
z = copysignf( x, y );
z = copysignf( x[ i%x.length ], y[ i%y.length ] );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
Original file line number Diff line number Diff line change
@@ -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;
@@ -44,11 +44,16 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var z;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = ( randu()*1.0e7 ) - 5.0e6;
z = copysignf( x, y );
z = copysignf( x[ i%x.length ], y[ i%y.length ] );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
Original file line number Diff line number Diff line change
@@ -91,16 +91,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 = copysignf( x, y );
z = copysignf( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Original file line number Diff line number Diff line change
@@ -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_copysignf( x, y );
z = stdlib_base_copysignf( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Loading
Oops, something went wrong.