Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object keys as array - remove first
(version: 0)
Comparing performance of:
Lo vs Filter / Map vs Map / Delete vs Reduce vs Slice vs Yielder
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var AssetCategory = { NONE3: 'NONE3', AVESSEL23: 'VESSEL23', NONE4: 'NONE3', AVESSEL24: 'VESSEL23', }
Tests:
Lo
_(AssetCategory).omit([AssetCategory.NONE3]).values().value()
Filter / Map
Object.keys(AssetCategory).filter(x => x !== AssetCategory.NONE3);
Map / Delete
var map = new Map(Object.entries(AssetCategory)); map.delete("NONE3") Array.from(map.keys());
Reduce
Object.keys(AssetCategory) .reduce( (res, x, i) => { if(x !== 'NONE3') { res.push(x); } return res; }, [] );
Slice
Object.keys(AssetCategory).slice(1)
Yielder
function *magic(col, token) { for(var i = 0; i < col.length; i++) { if(col[i] !== token) { yield col[i]; } } } Array.from(magic(Object.keys(AssetCategory), 'NONE3'));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Lo
Filter / Map
Map / Delete
Reduce
Slice
Yielder
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its individual test cases. **Benchmark Overview** The benchmark measures how different approaches can be used to remove a specific key ("NONE3") from an object (`AssetCategory`). The goal is to determine which method is the fastest. **Options Compared** There are six test cases: 1. **Slice**: Using the `slice()` method to extract an array of keys, starting from index 1 (skipping "NONE3"). 2. **Reduce**: Using the `reduce()` method to create a new array with only the keys that don't match "NONE3". 3. **Filter/Map**: Combining the `filter()` and `map()` methods to remove "NONE3" from the object's keys. 4. **Map/Delete**: Creating a new Map from the object's entries, deleting the key-value pair for "NONE3", and then iterating over the remaining keys. 5. **Yielder**: Using a generator function to iterate over the keys, skipping "NONE3". 6. **Lo** (no clear name): This test case seems to be a baseline or a reference point, as its benchmark result is not comparable to the others. **Pros and Cons of Each Approach** 1. **Slice**: Fast, but it requires knowing the index of the key to skip. * Pros: Simple and efficient. * Cons: May not work for objects with dynamic keys or large numbers of entries. 2. **Reduce**: Can be slow if the accumulator object is large or complex. * Pros: Flexible and works well with large datasets. * Cons: May have performance issues due to the overhead of creating an accumulator object. 3. **Filter/Map**: Can be slower than other approaches, as it involves multiple method calls. * Pros: Easy to understand and implement. * Cons: May not be as efficient as other methods. 4. **Map/Delete**: Creates a new Map, which can be memory-intensive. * Pros: Efficiently removes the key-value pair. * Cons: Can consume more memory than other approaches. 5. **Yielder**: Uses a generator function, which can be slower due to the overhead of creating and managing generators. * Pros: Easy to understand and implement. * Cons: May not be as efficient as other methods. **Libraries Used** The benchmark uses Lodash (version 4.17.4), specifically the `omit()` method, which is used in one of the test cases (`Filter/Map`). **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes mentioned in the benchmark. **Other Alternatives** Other approaches to remove a key from an object might include: * Using a regular expression to filter out specific keys * Utilizing `Object.fromEntries()` and then filtering the resulting array of key-value pairs * Employing a custom function to manipulate the object's properties directly Keep in mind that the optimal approach may depend on the specific requirements and constraints of your project.
Related benchmarks:
CircleSmallTest
asdasdasdasd
asdasdasdhgdth5454455454
Filter and return property values of an array of objects
Comments
Confirm delete:
Do you really want to delete benchmark?