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 assert/is-boolean benchmarks to measure affirmative/negative test values #1458

Merged
merged 1 commit into from
Mar 3, 2024
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
124 changes: 109 additions & 15 deletions lib/node_modules/@stdlib/assert/is-boolean/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

/* eslint-disable no-new-wrappers, no-empty-function */
/* eslint-disable no-empty-function */

'use strict';

Expand All @@ -30,7 +30,32 @@ var isBoolean = require( './../lib' );

// MAIN //

bench( pkg+'::primitives', function benchmark( b ) {
bench( pkg+'::primitives,true', function benchmark( b ) {
var values;
var bool;
var i;

values = [
true,
false
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBoolean( values[ i % values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean.isPrimitive( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::primitives,false', function benchmark( b ) {
var values;
var bool;
var i;
Expand All @@ -39,8 +64,6 @@ bench( pkg+'::primitives', function benchmark( b ) {
'5',
5,
NaN,
true,
false,
null,
void 0
];
Expand All @@ -60,16 +83,40 @@ bench( pkg+'::primitives', function benchmark( b ) {
b.end();
});

bench( pkg+'::objects', function benchmark( b ) {
bench( pkg+'::objects,true', function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Boolean( true ),
new Boolean( false )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBoolean( values[ i % values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean.isPrimitive( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::objects,false', function benchmark( b ) {
var values;
var bool;
var i;

values = [
[],
{},
function noop() {},
new Boolean( true )
function noop() {}
];

b.tic();
Expand All @@ -87,7 +134,32 @@ bench( pkg+'::objects', function benchmark( b ) {
b.end();
});

bench( pkg+'::primitives:isPrimitive', function benchmark( b ) {
bench( pkg+'::primitives:isPrimitive,true', function benchmark( b ) {
var values;
var bool;
var i;

values = [
true,
false
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBoolean.isPrimitive( values[ i % values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean.isPrimitive( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::primitives:isPrimitive,false', function benchmark( b ) {
var values;
var bool;
var i;
Expand All @@ -96,8 +168,6 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) {
'5',
5,
NaN,
true,
false,
null,
void 0
];
Expand All @@ -117,7 +187,7 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) {
b.end();
});

bench( pkg+'::objects:isPrimitive', function benchmark( b ) {
bench( pkg+'::objects:isPrimitive,false', function benchmark( b ) {
var values;
var bool;
var i;
Expand All @@ -144,7 +214,7 @@ bench( pkg+'::objects:isPrimitive', function benchmark( b ) {
b.end();
});

bench( pkg+'::primitives:isObject', function benchmark( b ) {
bench( pkg+'::primitives:isObject,false', function benchmark( b ) {
var values;
var bool;
var i;
Expand Down Expand Up @@ -174,16 +244,40 @@ bench( pkg+'::primitives:isObject', function benchmark( b ) {
b.end();
});

bench( pkg+'::objects:isObject', function benchmark( b ) {
bench( pkg+'::objects:isObject,true', function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Boolean( true ),
new Boolean( false )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBoolean.isObject( values[ i % values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean.isPrimitive( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::objects:isObject,false', function benchmark( b ) {
var values;
var bool;
var i;

values = [
[],
{},
function noop() {},
new Boolean( true )
function noop() {}
];

b.tic();
Expand Down
Loading