Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Things
(version: 0)
Comparing performance of:
keys vs entries vs copy
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
keys
const NULL_VALUES = [null, undefined, ''] const input = { bool: true, date: '01-01-1994', duration: '1d', formatted: '123.00', arr: [{ str: 'string', arr: [{ date: '01-01-1994', }, ], duration: '1d', obj: { formatted: '123.00', }, }, ], obj: { date: '01-01-1994', arr: [ '1d', { formatted: '123.00', }, ], }, } function extractCustomType(result, refs = new Set()) { if (NULL_VALUES.includes(result) || ['number', 'string', 'boolean'].includes(typeof result)) return result const proto = Object.getPrototypeOf(result) if (!proto) return result if (refs.has(result)) return result refs.add(result) if (['escape', 'literal'].includes(proto.constructor.name)) return extractCustomType(result.params[0], refs) // it is Formula if (result.toObject instanceof Function) return result.toObject() if (Array.isArray(result)) return result.map(each => extractCustomType(each, refs)) if (proto.constructor.name === 'Object') { return Object.keys(result).reduce((acc, key) => { if (!(result[key] instanceof Function)) acc[key] = extractCustomType(result[key], refs) return acc }, {}) } return result } extractCustomType(input)
entries
const NULL_VALUES = [null, undefined, ''] const input = { bool: true, date: '01-01-1994', duration: '1d', formatted: '123.00', arr: [{ str: 'string', arr: [{ date: '01-01-1994', }, ], duration: '1d', obj: { formatted: '123.00', }, }, ], obj: { date: '01-01-1994', arr: [ '1d', { formatted: '123.00', }, ], }, } function extractCustomType(result, refs = new Set()) { if (NULL_VALUES.includes(result) || ['number', 'string', 'boolean'].includes(typeof result)) return result const proto = Object.getPrototypeOf(result) if (!proto) return result if (refs.has(result)) return result refs.add(result) if (['escape', 'literal'].includes(proto.constructor.name)) return extractCustomType(result.params[0], refs) // it is Formula if (result.toObject instanceof Function) return result.toObject() if (Array.isArray(result)) return result.map(each => extractCustomType(each, refs)) if (proto.constructor.name === 'Object') { return Object.entries(result).reduce((acc, [key, value]) => { if (!(value instanceof Function)) acc[key] = extractCustomType(value, refs) return acc }, {}) } return result } extractCustomType(input)
copy
const NULL_VALUES = [null, undefined, ''] const input = { bool: true, date: '01-01-1994', duration: '1d', formatted: '123.00', arr: [{ str: 'string', arr: [{ date: '01-01-1994', }, ], duration: '1d', obj: { formatted: '123.00', }, }, ], obj: { date: '01-01-1994', arr: [ '1d', { formatted: '123.00', }, ], }, } function extractCustomType(result, refs = new Set()) { if (NULL_VALUES.includes(result) || ['number', 'string', 'boolean'].includes(typeof result)) return result const proto = Object.getPrototypeOf(result) if (!proto) return result if (refs.has(result)) return result refs.add(result) if (['escape', 'literal'].includes(proto.constructor.name)) return extractCustomType(result.params[0], refs) // it is Formula if (result.toObject instanceof Function) return result.toObject() if (Array.isArray(result)) return result.map(each => extractCustomType(each, refs)) if (proto.constructor.name === 'Object') { return Object.entries(result).reduce((acc, [key, value]) => { if (value instanceof Function) return acc return { ...acc, [key]: extractCustomType(value, refs) } }, {}) } return result } extractCustomType(input)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
keys
entries
copy
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; rv:123.0) Gecko/20100101 Firefox/123.0
Browser/OS:
Firefox 123 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
keys
387335.2 Ops/sec
entries
356759.6 Ops/sec
copy
248573.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Definition** The benchmark definition is a JavaScript function that extracts custom types from an input object. The function `extractCustomType` takes two arguments: `result` (the input object) and `refs` (an optional set of references). **Options Compared** Three options are compared: 1. **keys**: Extracts keys from the input object. 2. **entries**: Extracts entries from the input object (i.e., key-value pairs). 3. **copy**: Creates a copy of the input object. Each option is implemented differently, using different methods to extract custom types. **Testing** The benchmark tests each option by executing the `extractCustomType` function with the same input object (`input`) and measuring the execution time for each option. **What's Being Tested?** It appears that the benchmark is testing the performance of three different ways to extract custom types from an object. Specifically, it's testing: 1. Extracting keys from an object. 2. Extracting entries (key-value pairs) from an object. 3. Creating a copy of an object. **Results** The latest benchmark result shows the execution time for each option on a Desktop platform with Mac OS X 10.15 and Firefox 123: | TestName | ExecutionsPerSecond | | --- | --- | | keys | 387335.25 | | entries | 356759.625 | | copy | 248573.25 | The results suggest that the `keys` option is the fastest, followed by `entries`, and then `copy`. **Insights** Based on the benchmark results, we can infer some insights: * Extracting keys from an object might be faster because it requires less computation. * Extracting entries (key-value pairs) from an object might require more memory access or computation, making it slower than extracting keys. * Creating a copy of an object is likely to be the slowest option due to the overhead of creating a new object and copying its contents.
Related benchmarks:
tstssss
Find vs some lodash
Lodash.get vs Property dot notation deeply nested
Lodash.get vs Property dot notation deeply vs optional chaining
Object values using find vs lodash find
Comments
Confirm delete:
Do you really want to delete benchmark?