Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object mapping vs array
(version: 0)
Comparing performance of:
Array vs Object mapping
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Array
const zoneSchedulesData = [ { id: 1, zone: { id: 1 } }, { id: 2, zone: { id: 1 } }, { id: 3, zone: { id: 2 } }, { id: 4, zone: { id: 2 } }, { id: 5, zone: { id: 1 } } ]; const rawsData = [ { id: 1, zoneSchedule: { id: 1 } }, { id: 2, zoneSchedule: { id: 1 } }, { id: 3, zoneSchedule: { id: 2 } }, { id: 4, zoneSchedule: { id: 2 } }, { id: 5, zoneSchedule: { id: 1 } }, { id: 1, zoneSchedule: { id: 3 } }, { id: 2, zoneSchedule: { id: 3 } }, { id: 3, zoneSchedule: { id: 3 } }, { id: 4, zoneSchedule: { id: 4 } }, { id: 5, zoneSchedule: { id: 3 } }, { id: 5, zoneSchedule: { id: 4 } }, { id: 5, zoneSchedule: { id: 5 } } ]; const zoneId = 1 const array = () => { const zoneSchedules = zoneSchedulesData.filter(zs => zs.zone.id === zoneId) const zonescheduleIds = zoneSchedules.map(zs => zs.id) return raws.filter(raw => zonescheduleIds.includes(raw.zoneSchedule.id)) }
Object mapping
const zoneSchedules = { "1": { id: 1, zone: { id: 1 } }, "2": { id: 2, zone: { id: 1 } }, "3": { id: 3, zone: { id: 2 } }, "4": { id: 4, zone: { id: 2 } }, "5": { id: 5, zone: { id: 1 } } }; const raws = { "1": { id: 1, zoneSchedule: { id: 1 } }, "2": { id: 2, zoneSchedule: { id: 1 } }, "3": { id: 3, zoneSchedule: { id: 2 } }, "4": { id: 4, zoneSchedule: { id: 2 } }, "5": { id: 5, zoneSchedule: { id: 1 } }, "6": { id: 6, zoneSchedule: { id: 3 } }, "7": { id: 7, zoneSchedule: { id: 3 } }, "8": { id: 8, zoneSchedule: { id: 3 } }, "9": { id: 9, zoneSchedule: { id: 4 } }, "10": { id: 10, zoneSchedule: { id: 3 } }, "11": { id: 11, zoneSchedule: { id: 4 } }, "12": { id: 12, zoneSchedule: { id: 5 } } }; const zoneId = 1 const array = () => { const zoneSchedules = Object.values(zoneSchedulesData).filter(zs => zs.zone.id === zoneId) const zonescheduleIds = zoneSchedules.map(zs => zs.id) return Object.values(raws).filter(raw => zonescheduleIds.includes(raw.zoneSchedule.id)) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array
Object mapping
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):
I'd be happy to help you understand the JavaScript microbenchmark on MeasureThat.net. **Benchmark Definition** The benchmark is called "Object mapping vs array". It tests two approaches: object mapping and array-based filtering. **Options compared** 1. **Object Mapping**: This approach uses an object (specifically, `zoneSchedulesData`) with zone IDs as keys to filter the data. 2. **Array-Based Filtering**: This approach uses a JavaScript array (`raws`) with raw zone schedule IDs to filter the data. **Pros and Cons of each approach** **Object Mapping:** Pros: * Can be more efficient for small datasets, since it allows for direct access to the desired data. * Can reduce memory allocation and copying overhead compared to creating an array. Cons: * May require additional processing steps (e.g., handling duplicate keys) that can add overhead. * Might not scale well for large datasets, since the object structure needs to be maintained. **Array-Based Filtering:** Pros: * Scalable for larger datasets, as it uses a standard JavaScript array data structure. * Can be more flexible with filtering logic, as it allows for arbitrary predicate functions. Cons: * May require additional memory allocation and copying overhead compared to object mapping. * Can be slower due to the overhead of creating an array and iterating over its elements. **Library usage** Neither approach relies on a specific JavaScript library. However, if we look at the `zoneSchedulesData` and `raws` objects, we can see that they are using JSON data structures. This is likely due to the fact that these are string representations of the data, which can be easily shared between different environments. **Benchmark results** The latest benchmark result shows two runs: one for object mapping (`Object mapping`) and one for array-based filtering (`Array`). The results indicate that: * Object mapping yields a higher number of executions per second (842,046,848) compared to array-based filtering (838,105,664). This suggests that the object mapping approach is slightly faster in this specific benchmark. However, it's essential to note that these results are only for this particular benchmark and may not generalize to other scenarios or datasets. Overall, the choice between object mapping and array-based filtering depends on the specific requirements of your use case. If you need to process small to medium-sized datasets with simple filtering logic, object mapping might be a good choice. For larger datasets or more complex filtering scenarios, array-based filtering might be a better option.
Related benchmarks:
Array.from() vs new Array() - map
Array.from() vs new Array().map()
new Map vs set array to map
Array Spread vs Fill vs New Array
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?