Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lodash pick vs native pick vs compiled fn pick
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Lodash
106.9 Ops/sec
native pick
802.7 Ops/sec
compiled function
665.8 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src=''> </script>
Script Preparation code:
function pick1(obj, keys) { var res = {}; if (typeof keys === 'string') { if (keys in obj) { res[keys] = obj[keys]; } return res; } var len = keys.length; var idx = -1; while (++idx < len) { var key = keys[idx]; if (key in obj) { res[key] = obj[key]; } } return res; }; var pick2 = new Function('el', 'if (!el) return {}; const res = {}; ' + 'if ("a" in el) res.a = el.a;' + 'if ("d" in el) res.d = el.d;' + 'if ("i" in el) res.i = el.i;' + ' return res;') function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive } var data = []; for (let i = 0; i < 10000; i++) { const obj = {}; const propsCount = getRandomInt(0, 10); for (let j = 0; j < propsCount; j++) { const propCode = getRandomInt(97, 122); obj[String.fromCharCode(propCode)] = propCode; } data.push(obj); }
Tests:
Lodash
data.map((obj) => _.pick(obj, ['a','d','i']))
native pick
data.map((obj) => pick1(obj, ['a','d','i']))
compiled function
data.map((obj) => pick2(obj, ['a','d','i']))