Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test map size 2
(version: 0)
Comparing performance of:
Size 10k vs Size 100k vs Size 1000k vs Constant
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script> function randomString() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; for( var i=0; i < 20; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } var randomKey = []; var randomVals = []; for (var i=0; i < 1001000; i++) { randomKey[i] = randomString(); randomVals[i] = randomString(); } </script>
Script Preparation code:
var map10k = new Map(); var map100k = new Map(); var map1000k = new Map(); for (var i=0; i < 10000; i++) { map10k.set(randomKey[i], randomVals[i]); } for (var i=0; i < 100000; i++) { map100k.set(randomKey[i], randomVals[i]); } for (var i=0; i < 1000000; i++) { map1000k.set(randomKey[i], randomVals[i]); }
Tests:
Size 10k
for (var i=0; i < 1000; i++) { var val = map10k.size; }
Size 100k
for (var i=0; i < 1000; i++) { var val = map100k.size; }
Size 1000k
for (var i=0; i < 1000; i++) { var val = map1000k.size; }
Constant
for (var i=0; i < 1000; i++) { var val = 42; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Size 10k
Size 100k
Size 1000k
Constant
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 world of MeasureThat.net, where JavaScript microbenchmarks come to life. **Benchmark Definition** The benchmark definition is represented by a JSON object that contains the script preparation code and HTML preparation code for the test. The script preparation code creates three instances of `Map` objects: `map10k`, `map100k`, and `map1000k`. Then, it populates these maps with random key-value pairs using loops. The HTML preparation code defines a function `randomString()` that generates a random string for each iteration. It also initializes two arrays, `randomKey` and `randomVals`, to store the generated keys and values, respectively. **Individual Test Cases** Each test case has a unique name, description, and benchmark definition. There are four test cases: 1. **Size 10k**: This test case iterates over the `size` property of `map10k` for 1000 iterations. 2. **Size 100k**: This test case iterates over the `size` property of `map100k` for 1000 iterations. 3. **Size 1000k**: This test case iterates over the `size` property of `map1000k` for 1000 iterations. 4. **Constant**: This test case simply returns a constant value (`42`) for 1000 iterations. **Options Compared** In this benchmark, two main options are being compared: * The size of the map: Creating maps with smaller sizes (10k and 100k) versus larger sizes (1000k). * Constant vs. dynamic value: Returning a constant value (`42`) versus accessing the `size` property of a map. **Pros and Cons** Here's a brief analysis of each option: 1. **Map size**: Creating maps with smaller sizes can lead to faster execution times, as there are fewer key-value pairs to process. However, this may not accurately represent real-world scenarios where map sizes can grow arbitrarily large. 2. **Constant vs. dynamic value**: Returning a constant value is generally faster than accessing the `size` property of a map, which involves a lookup and potentially more complex operations. **Library and Purpose** The `Map` object in JavaScript is used to create hash tables that store key-value pairs. The `size` property of a `Map` returns the number of key-value pairs stored in it. **Special JS Features or Syntax** This benchmark does not use any special JavaScript features or syntax, making it accessible to developers with varying levels of expertise. **Other Alternatives** If you were to recreate this benchmark, you might consider alternatives such as: * Using a different data structure, like an object or an array. * Adding more test cases to cover additional scenarios. * Incorporating other performance-related metrics, like memory usage or garbage collection pauses. Keep in mind that these alternatives would require adjustments to the script preparation code and potentially impact the benchmark's accuracy.
Related benchmarks:
Object vs Map
Test map size
comparing Map and object
Mappers
Comments
Confirm delete:
Do you really want to delete benchmark?