Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map to Array (100 and 10,000)
(version: 0)
This test exists to benchmark the conversion of Map().values() to an Array.
Comparing performance of:
Map to Array for 100 Items vs Map to Array for 10,000 Items
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Map to Array for 100 Items
var fooSet = new Map(); for(var i=0;i<100;i++) { fooSet.set(i, i); } var other = Array.from(fooSet);
Map to Array for 10,000 Items
var fooSet = new Map(); for(var i=0;i<10000;i++) { fooSet.set(i, i); } var other = Array.from(fooSet);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map to Array for 100 Items
Map to Array for 10,000 Items
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map to Array for 100 Items
134762.5 Ops/sec
Map to Array for 10,000 Items
294.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** MeasureThat.net is testing the performance of converting `Map()` instances to arrays using the `Array.from()` method. In other words, it's measuring how long it takes to iterate over a map and collect its values into an array. This benchmark is useful for understanding the performance characteristics of JavaScript's built-in data structures and methods. **Options being compared** There are two main options being compared: 1. **Converting a small map (100 items) to an array**: This test case is likely used to measure the overhead of converting a relatively small dataset. 2. **Converting a large map (10,000 items) to an array**: This test case is designed to evaluate the performance of the conversion process for larger datasets. **Pros and Cons** * **Conversion with `Array.from()`**: The most common way to convert a Map to an Array in modern JavaScript. It's generally considered the most efficient approach. + Pros: Widely supported, efficient, and easy to use. + Cons: May not be as optimized for smaller datasets, and some older browsers might have performance issues with this method. * **Manual iteration**: This approach involves iterating over the map using a `for...of` loop or another method of your choice. + Pros: Can be faster for very small datasets due to lower overhead. + Cons: More verbose, error-prone, and less efficient for larger datasets. **Library usage** None of the test cases use any external libraries. The `Array.from()` method is a built-in JavaScript function that converts a Map to an Array. **Special JS features or syntax** The benchmark doesn't rely on any specific special JavaScript features or syntax beyond what's required for the `Array.from()` function. **Other alternatives** If you wanted to measure the performance of converting Maps to Arrays using alternative methods, some options might include: 1. **Using a different array constructor**: Instead of `Array.from()`, you could use other constructors like `Array.create()` or even `new Array()`. 2. **Manual indexing**: If you knew the size of the Map and its values, you could manually create an indexed array to store the data. 3. **Other iteration methods**: Besides `for...of` loops, you could also explore using other iteration methods like `forEach()`, `map()`, or even Closures. Keep in mind that these alternatives would likely have different performance characteristics and might not be as efficient or readable as the original `Array.from()` approach.
Related benchmarks:
Map from .reduce vs Map from .map
Array.from() vs new Array() performance...
from vs map
Array vs Class
Array.from() vs new Array().map()
Comments
Confirm delete:
Do you really want to delete benchmark?