parse vs omit

Benchmark created on


Description

parse vs omit

Preparation HTML

<script src="
https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js
"></script>

Setup

var m = {};
const generateRandomString = () => {
  return Math.floor(Math.random() * Date.now()).toString(36);
};
m.secret = 'test'
m.clientSecret = 'test'
for(let i =0; i<100; i++){
	const s = generateRandomString();
	m[s] = s;
}

Test runner

Ready to run.

Testing in
TestOps/sec
parse
const m1 = JSON.parse(JSON.stringify(m));
delete m1.secret;
delete m1.clientSecret;
ready
omit
const m1 = {};
for(var k in m){
	if(k != 'secret' || k != 'clientSecret'){
		continue;
	}
	m1[k]=m[k]
}
ready
omit_
const m1 = _.omit(m,['secret','clientSecret'])
ready
omit 2 with array
const m1 = {};
const omary = ['clientSecret', 'secret'];
for(var k in m){
	if(omary.indexOf(k) >= 0){
		continue;
	}
	m1[k]=m[k]
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.