Skip to content

Instantly share code, notes, and snippets.

@chuyik chuyik/omit.js
Created Jul 25, 2018

Embed
What would you like to do?
Test _.omit performance
const speedy = require('speedy')
const _ = require('lodash')
/**
==================
Test Result
==================
Node v10.1.0
V8 v6.6.346.27-node.6
Speedy v0.1.1
Tests: 4
Timeout: 1000ms (1s 0ms)
Samples: 3
Total time per test: ~3000ms (3s 0ms)
Total time: ~12000ms (12s 0ms)
Higher is better (ops/sec)
babel
1,844,519 ± 11.4%
lodash
315,986 ± 12.0%
lodashOmitBy
295,410 ± 7.5%
objectSpread
326,861 ± 5.0%
Elapsed time: 12133ms (12s 133ms)
*/
var user = {
"_id": "123456789abcdefghijk",
"updatedAt": new Date("2018-07-13T01:43:13.516Z"),
"createdAt": new Date("2017-08-01T09:21:09.814Z"),
"username": "jackson",
"nickname": "Jackson",
"email": "jackson@nb.com",
"org_name": "group-company-system-depart-team",
"mobile": "13500000000",
"role": "designer",
"login_type": "local",
"__v": 0,
"applied_role": "designer",
"org_ok": true,
"banner_count": 100,
}
var con = {
babel: function () {
return _objectWithoutProperties(user, ["org_name"])
},
lodash: function () {
return _.omit(user, ["org_name"])
},
lodashOmitBy: function () {
return _.omitBy(user, (v, k) => k === 'org_name')
},
objectSpread: function () {
const { org_name, ...rest } = user
return rest
},
}
// Run Test
speedy.run(con);
// Debug
// for (let x in con) { console.log(x, con[x]()) }
function _objectWithoutProperties(obj, keys) {
var target = {};
for (var i in obj) {
if (keys.includes(i)) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.