Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Branching if-else-if, if-return, lodash cond v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
initial
12952432.0 Ops/sec
plain
13011911.0 Ops/sec
lodash
731275.9 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var TYPES = { A: 'a', B: 'b', C: 'c', CExt: 'c_ext', D: 'd', E: 'e', F: 'f', G: 'g', Other: 'Other', }; function isA(x) { return x.type === 'a'; } function isB(x) { return x.type === 'b'; } function isC(x) { return x.type === 'c'; } function isExt(x) { return x.type.indexOf('_ext') >= 0; } function isD(x) { return x.type === 'd'; } function isE(x) { return x.type === 'e'; } function isF(x) { return x.type === 'f'; } function isG(x) { return x.type === 'g'; } var testData = [{ type: 'a'}, { type: 'c'}, { type: 'c_ext'}, { type: 'z'}, { type: 'f'}];
Tests:
initial
function getType(x) { if (isA(x)) { return TYPES.A; } else if (isB(x)) { return TYPES.B; } else if(isC(x)) { if (isExt(x)) { return TYPES.CExt; } return TYPES.C; } else if(isD(x)) { return TYPES.D; } else if(isE(x)){ return TYPES.E; } else if(isF(x)) { return TYPES.F; } else if(isG(x)) { return TYPES.G; } return TYPES.Other; } testData.map(getType);
plain
function getTypePlain(x) { if (isA(x)) { return TYPES.A; } if (isB(x)) { return TYPES.B; } if(isC(x)) { if (isExt(x)) { return TYPES.CExt; } return TYPES.C; } if(isD(x)) { return TYPES.D; } if(isE(x)){ return TYPES.E; } if(isF(x)) { return TYPES.F; } if(isG(x)) { return TYPES.G; } return TYPES.Other; } testData.map(getTypePlain);
lodash
var _getType = _.cond([ [isA, _.constant(TYPES.A)], [isB, _.constant(TYPES.B)], [isC, _.cond([ [isExt, _.constant(TYPES.Ext)], [_.stubTrue, _.constant(TYPES.C)] ])], [isD, _.constant(TYPES.D)], [isE, _.constant(TYPES.E)], [isF, _.constant(TYPES.F)], [isG, _.constant(TYPES.G)], [_.stubTrue, _.constant(TYPES.Other)], ]); testData.map(_getType);