Benchmark: is, is_js, thiis, chai, vanilla

node v18.11.0
version: 2.0.6
endpointsharetweet
This is a playground to test performance between packages: is, is_js, thiis, chai, vanilla
var benchmark = require("benchmark"); var iss = require("is"); var is_js = require("is_js"); var {is} = require("thiis"); const chai = require('chai'); chai.should(); function isNonEmptyObject(variable) { return typeof variable === 'object' && variable !== null && !Array.isArray(variable) && Object.keys(variable).length > 0; } var data = {a: 1}; var count = 1000000; console.time('is') for (let i = 0; i < count; i++) { if (iss.object(data) && !iss.empty(data)) { } } console.timeEnd('is'); console.time('thiis') for (let i = 0; i < count; i++) { if (is.object_not_empty(data)) { } } console.timeEnd('thiis'); console.time('is_js') for (let i = 0; i < count; i++) { if (is_js.object(data) && is_js.not.empty(data)) { } } console.timeEnd('is_js'); console.time('chai') for (let i = 0; i < count; i++) { if (data.should.not.be.empty) { } } console.timeEnd('chai'); console.time('vanilla') for (let i = 0; i < count; i++) { if (isNonEmptyObject(data)) { } } console.timeEnd('vanilla'); var suite = new benchmark.Suite; // add tests suite.add('is', function() { if (iss.object(data) && !iss.empty(data)) { } }) .add('thiis', function() { if (is.object_not_empty(data)) { } }) .add('is_js', function() { if (is_js.object(data) && is_js.not.empty(data)) { } }) .add('chai', function() { if (data.should.not.be.empty) { } }) .add('vanilla', function() { if (isNonEmptyObject(data)) { } }) // add listeners .on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')); }) // run async .run({ 'async': true });
Loading…

no comments

    sign in to comment