Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
montest
(version: 0)
montest
Comparing performance of:
Array.find, 3 elements vs Map.get, 3 elements vs Array.find, 10 elements vs Map.get, 10 elements vs Clone array 3 vs Clone map 3 vs Clone array 10 vs Clone map 10
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomElement(id) { return { id, a: Math.random(), b: Math.random(), c: Math.random(), } } function getArray(length) { const result = []; for (let i = 0; i < length; i++) { result.push(getRandomElement(i)) } return result; } function arrayToMap(array) { return new Map(array.map(el => [el.id, el])); } function cloneArray(array) { return [...array]; } function cloneMap(map) { return new Map(map); } function getRandomInt(max) { return Math.floor(Math.random() * max); } array_small = getArray(3); array_large = getArray(10); map_small = arrayToMap(array_small); map_large = arrayToMap(array_large);
Tests:
Array.find, 3 elements
const target = getRandomInt(2); array_small.find(el => el.id === target);
Map.get, 3 elements
const target = getRandomInt(2); map_small.get(target);
Array.find, 10 elements
const target = getRandomInt(9); array_large.find(el => el.id === target);
Map.get, 10 elements
const target = getRandomInt(9); map_large.get(target)
Clone array 3
const array = cloneArray(array_small);
Clone map 3
const map = cloneMap(map_small);
Clone array 10
const array = cloneArray(array_large);
Clone map 10
const map = cloneMap(map_large);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
Array.find, 3 elements
Map.get, 3 elements
Array.find, 10 elements
Map.get, 10 elements
Clone array 3
Clone map 3
Clone array 10
Clone map 10
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 what is being tested in this benchmark. **Benchmark Definition** The benchmark definition json contains several functions that are used to generate test cases: 1. `getRandomElement(id)`: generates a random object with three properties (`a`, `b`, and `c`) for each `id` passed as an argument. 2. `getArray(length)`: creates an array of length `length` by pushing random objects generated by `getRandomElement(i)` into the array. 3. `arrayToMap(array)`: converts an array to a Map by mapping each object in the array to a key-value pair in the Map, where the key is the `id` property of the object and the value is the object itself. 4. `cloneArray(array)`: creates a shallow copy of the input array by spreading its elements into a new array. 5. `cloneMap(map)`: creates a shallow copy of the input Map by spreading its key-value pairs into a new Map. **Individual Test Cases** Each test case is a simple benchmark that exercises one of these functions: 1. **Array.find**: finds an element in the `array_small` array that matches the condition specified in the `Benchmark Definition`. In this case, it's finding an object with `id === target`, where `target` is a random integer between 0 and 2. 2. **Map.get**: retrieves a value from the `map_small` Map using the key-value pair specified in the `Benchmark Definition`. 3. **Clone array**: creates a copy of the `array_small` array by calling `cloneArray(array_small)`. 4. **Clone map**: creates a copy of the `map_small` Map by calling `cloneMap(map_small)`. **Performance Comparison** The benchmark measures the execution time of each test case across multiple runs, with different random targets for each element in the arrays and maps. This allows the benchmark to accurately compare the performance characteristics of each function under various conditions. **Interpretation** Based on the results, we can see that: * `array.find` is generally the slowest operation, likely due to the need to iterate through the array and find a matching element. * `map.get` is faster than `array.find`, possibly because Maps provide faster lookup times. * `cloneArray` and `cloneMap` are relatively fast operations, as they only require creating a new array or Map with existing data. Overall, this benchmark provides a useful comparison of the performance characteristics of these three functions, which can help developers choose the best approach for their specific use case.
Related benchmarks:
Array.find vs. Map.getss
Array.find vs. Map.get fork
Array.find vs. Map.get fork2
Array.find vs. Map.get 300
Comments
Confirm delete:
Do you really want to delete benchmark?