Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test json vs omit
(version: 0)
Comparing performance of:
omit vs json
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var MyColl = [{ description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } },{ description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } } , { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }, { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } } ]
Tests:
omit
const a = MyColl.map(i => _.omit(i, ['myBoolean', 'myNumber']))
json
const a = JSON.parse(JSON.stringify(MyColl, ['description', 'jayson']))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
omit
json
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
omit
508507.0 Ops/sec
json
768964.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing two approaches to create a deep copy of an object: 1. Using `lodash omit` function (`const a = MyColl.map(i => _.omit(i, ['myBoolean', 'myNumber']))`) 2. Using `JSON.parse(JSON.stringify(MyColl, ['description', 'jayson']))` **Options Being Compared** The two options being compared are: * Using the `_.omit()` function from Lodash to exclude specific properties from the object copy. * Using the `JSON.parse()` and `JSON.stringify()` methods with a custom replacer function to create a deep copy of the object. **Pros and Cons of Each Approach** 1. **Lodash Omit Function** * Pros: + Fast and efficient + Easy to use and understand * Cons: + Requires Lodash library, which may add extra dependencies 2. **JSON.parse() and JSON.stringify() with Replacer Function** * Pros: + Native JavaScript functions, no additional libraries required + Can handle complex object structures and custom data types * Cons: + May be slower than Lodash's `_.omit()` function due to the overhead of parsing and stringifying JSON + Requires careful configuration of the replacer function to exclude specific properties **Library and Purpose** In this benchmark, Lodash is used as a utility library for its `_.omit()` function. The purpose of this function is to exclude specific properties from an object copy. **Special JS Feature or Syntax** There isn't any special JavaScript feature or syntax being tested in this benchmark. However, it's worth noting that the use of Lodash and the `JSON.parse()`/`JSON.stringify()` approach may require some familiarity with these concepts for developers who are not already comfortable working with them. **Other Alternatives** Other alternatives to create a deep copy of an object could include: * Using the `Object.assign()` method with the spread operator (`{ ...obj }`) * Using a library like Immutable.js or Ramda, which provide functional programming utilities for creating immutable data structures. * Implementing a custom deep copying function using recursion and/or iteration. However, these alternatives may not be as efficient or straightforward to use as the Lodash `_.omit()` function or the `JSON.parse()`/`JSON.stringify()` approach.
Related benchmarks:
Lodash cloneDeep vs JSON Clone deeper1
lodash clonedeep vs json.parse(stringify()) vs recursivecopy new big
JSON.parse vs object literal
Plain Json: lodash clonedeep vs json.parse(stringify())
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone with a simple and a more deep test
Comments
Confirm delete:
Do you really want to delete benchmark?