Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,8 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isEven = require( './../lib' );
Expand All @@ -31,14 +30,19 @@ var isEven = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var y;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = isEven( float64ToInt32( x ) );
y = isEven( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -40,14 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var x;
var y;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = iseven( float64ToInt32( x ) );
y = iseven( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double x[ 100 ];
double t;
bool b;
int i;

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

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double() * 200.0 ) - 100.0;
b = stdlib_base_int32_is_even( (int32_t)x );
b = stdlib_base_int32_is_even( (int32_t)x[ i%100 ] );
if ( b != true && b != false ) {
printf( "should return either true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function returns `true` if provided `0`', function test( t ) {
var bool = isEven( 0 );
t.strictEqual( bool, true, 'returns true when provided 0' );
t.strictEqual( bool, true, 'returns expected value' );
t.end();
});

Expand All @@ -55,7 +55,7 @@ tape( 'the function returns `true` if provided an even integer', function test(
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
x *= 2; // always even
bool = isEven( x );
t.strictEqual( bool, true, 'returns true when provided '+x );
t.strictEqual( bool, true, 'returns expected value when provided '+x );
}
t.end();
});
Expand All @@ -73,7 +73,7 @@ tape( 'the function returns `false` if provided an odd integer', function test(
x += 1;
}
bool = isEven( x );
t.strictEqual( bool, false, 'returns false when provided '+x );
t.strictEqual( bool, false, 'returns expected value when provided '+x );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'the function returns `true` if provided `0`', opts, function test( t ) {
var bool = iseven( 0 );
t.strictEqual( bool, true, 'returns true when provided 0' );
t.strictEqual( bool, true, 'returns expected value' );
t.end();
});

Expand All @@ -60,7 +60,7 @@ tape( 'the function returns `true` if provided an even integer', opts, function
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
x *= 2; // always even
bool = iseven( x );
t.strictEqual( bool, true, 'returns true when provided '+x );
t.strictEqual( bool, true, 'returns expected value when provided '+x );
}
t.end();
});
Expand All @@ -78,7 +78,7 @@ tape( 'the function returns `false` if provided an odd integer', opts, function
x += 1;
}
bool = iseven( x );
t.strictEqual( bool, false, 'returns false when provided '+x );
t.strictEqual( bool, false, 'returns expected value when provided '+x );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isOdd = require( './../lib' );
Expand All @@ -31,14 +30,19 @@ var isOdd = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var y;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = isOdd( float64ToInt32( x ) );
y = isOdd( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var float64ToInt32 = require( '@stdlib/number/float64/base/to-float32' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -40,14 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var x;
var y;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = isOdd( float64ToInt32( x ) );
y = isOdd( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double x[ 100 ];
double t;
bool b;
int i;

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

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double() * 200.0 ) - 100.0;
b = stdlib_base_int32_is_odd( (int32_t)x );
b = stdlib_base_int32_is_odd( (int32_t)x[ i%100 ] );
if ( b != true && b != false ) {
printf( "should return either true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function returns `false` if provided `0`', function test( t ) {
var bool = isOdd( 0 );
t.strictEqual( bool, false, 'returns false when provided 0' );
t.strictEqual( bool, false, 'returns expected value' );
t.end();
});

Expand All @@ -55,7 +55,7 @@ tape( 'the function returns `false` if provided an even integer', function test(
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
x *= 2; // always even
bool = isOdd( x );
t.strictEqual( bool, false, 'returns false when provided '+x );
t.strictEqual( bool, false, 'returns expected value when provided '+x );
}
t.end();
});
Expand All @@ -73,7 +73,7 @@ tape( 'the function returns `true` if provided an odd integer', function test( t
x += 1;
}
bool = isOdd( x );
t.strictEqual( bool, true, 'returns true when provided '+x );
t.strictEqual( bool, true, 'returns expected value when provided '+x );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'the function returns `false` if provided `0`', opts, function test( t ) {
var bool = isOdd( 0 );
t.strictEqual( bool, false, 'returns false when provided 0' );
t.strictEqual( bool, false, 'returns expected value' );
t.end();
});

Expand All @@ -60,7 +60,7 @@ tape( 'the function returns `false` if provided an even integer', opts, function
x = round( randu()*MAX_INT32 ) - HALF_MAX_INT32 - 1;
x *= 2; // always even
bool = isOdd( x );
t.strictEqual( bool, false, 'returns false when provided '+x );
t.strictEqual( bool, false, 'returns expected value when provided '+x );
}
t.end();
});
Expand All @@ -78,7 +78,7 @@ tape( 'the function returns `true` if provided an odd integer', opts, function t
x += 1;
}
bool = isOdd( x );
t.strictEqual( bool, true, 'returns true when provided '+x );
t.strictEqual( bool, true, 'returns expected value when provided '+x );
}
t.end();
});