Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object test with unicode
(version: 0)
Comparing performance of:
Map vs Object
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var N_TRIES = 5000000; var GENDER_FEMALE = 0; var GENDER_MALE = 1; var obj = { '\u{1f937}': GENDER_FEMALE, '\u{1f938}': GENDER_MALE, '\u{1f939}': GENDER_MALE, '\u{1f6a3}': GENDER_MALE, '\u{1f575}': GENDER_MALE, '\u{1f646}': GENDER_FEMALE, '\u{1f647}': GENDER_MALE, '\u{1f645}': GENDER_FEMALE, '\u{1f46f}': GENDER_FEMALE, '\u{1f46e}': GENDER_MALE, '\u{1f926}': GENDER_MALE, '\u{1f471}': GENDER_MALE, '\u{1f9d8}': GENDER_FEMALE, '\u{1f473}': GENDER_MALE, '\u{1f6b6}': GENDER_MALE, '\u{1f477}': GENDER_MALE, '\u{1f9de}': GENDER_FEMALE, '\u{1f3c4}': GENDER_MALE, '\u{1f3c3}': GENDER_MALE, '\u{1f9d7}': GENDER_FEMALE, '\u{1f9d6}': GENDER_MALE, '\u{26f9}': GENDER_MALE, '\u{1f9df}': GENDER_FEMALE, '\u{1f481}': GENDER_FEMALE, '\u{1f482}': GENDER_MALE, '\u{1f6b4}': GENDER_MALE, '\u{1f6b5}': GENDER_MALE, '\u{1f486}': GENDER_FEMALE, '\u{1f487}': GENDER_FEMALE, '\u{1f9dd}': GENDER_MALE, '\u{1f9da}': GENDER_FEMALE, '\u{1f9dc}': GENDER_FEMALE, '\u{1f9db}': GENDER_FEMALE, '\u{1f3cb}': GENDER_MALE, '\u{1f3cc}': GENDER_MALE, '\u{1f3ca}': GENDER_MALE, '\u{1f64d}': GENDER_FEMALE, '\u{1f64e}': GENDER_FEMALE, '\u{1f64b}': GENDER_FEMALE, '\u{1f9d9}': GENDER_FEMALE, '\u{1f93c}': GENDER_MALE, '\u{1f93d}': GENDER_MALE, '\u{1f93e}': GENDER_FEMALE, }; var map = new Map(Object.entries(obj)); var elems = Object.keys(obj);
Tests:
Map
for (let j = 0; j < elems.length; ++j) { map.get(elems[j]); }
Object
for (let j = 0; j < elems.length; ++j) { obj[elems[j]]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map
Object
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 dive into the explanation of the provided benchmark. **What is being tested?** The benchmark is testing two approaches to access and retrieve values from a data structure: Maps (`map`) and Objects (`obj`). **Options compared:** Two options are being compared: 1. **Map**: Using a `Map` data structure to store key-value pairs, where each key is unique and corresponds to a specific value. 2. **Object**: Using an Object literal to store key-value pairs, where each key is a string (a Unicode character in this case) and corresponds to a specific value. **Pros and Cons:** **Map:** Pros: * Efficient lookups: Maps use hash tables, which provide fast lookup times (O(1)) for keys. * No collisions: Each key-value pair is unique, eliminating the need for collision resolution. Cons: * Additional memory overhead: Maps require more memory to store the underlying data structure. * Limited iteration order: Iterating over a Map can be non-deterministic due to hash table behavior. **Object:** Pros: * Lightweight: Objects require less memory compared to Maps. * Deterministic iteration order: Iterating over an Object is guaranteed in a specific order (by key). Cons: * Slow lookups: Objects use linear search, which has a time complexity of O(n), making lookups slower for large datasets. **Other considerations:** In this benchmark, the test cases are designed to measure the execution speed of accessing and retrieving values from both Maps and Objects. The `elems` array is used as keys in both data structures, and the test case iterates over these elements to access their corresponding values. **Library and syntax features:** * No specific libraries are mentioned in the benchmark definition or individual test cases. * No special JavaScript features or syntax are being tested; it appears to be a basic comparison of Map and Object performance. **Alternatives:** Other data structures that could be used for this benchmark include: * Arrays with indices * Sets (for fast lookups, but potentially slower iteration) * Hash tables specifically designed for JavaScript (e.g., `Object.create()`, `Map()`) Keep in mind that these alternatives might affect the results of the benchmark and may not provide the same level of performance as Maps or Objects.
Related benchmarks:
Accent Mark Removal
Yeahaaa
Create Object vs Map vs Array vs Set
Encode byte string test (string concatenation vs. map join)
Comments
Confirm delete:
Do you really want to delete benchmark?