Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Reverse array / reverse vs map
(version: 0)
Comparing performance of:
ES Reverse / in place vs ES map
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
test = ["a", "b", "c", "d", "e"];
Tests:
ES Reverse / in place
test.reverse()
ES map
[...test].map(test.pop, test)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ES Reverse / in place
ES map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ES Reverse / in place
73725328.0 Ops/sec
ES map
47644748.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark with two test cases: Reverse array / reverse vs map. This benchmark tests the performance of reversing an array in place versus using the `map()` method. **Test Cases** There are two test cases: 1. **ES Reverse / in place**: This test case uses the `reverse()` method to reverse the array in place. 2. **ES map**: This test case uses the `map()` method with a callback function to create a new array with the reversed elements. **Options Compared** The two test cases are compared in terms of their performance on reversing an array. **Pros and Cons of Different Approaches** 1. **In-Place Reversal (ES Reverse)**: * Pros: It modifies the original array, so it only requires a single memory allocation. * Cons: It can be slower than creating a new array due to the overhead of modifying the existing array. 2. **Creating a New Array with map (ES Map)**: * Pros: It creates a new array, which can be faster than in-place reversal for large arrays. * Cons: It requires additional memory allocation and copying of elements. **Library Used** The `map()` method is used with a callback function to create a new array. The library used here is the built-in JavaScript `Array.prototype.map()` method. **Special JS Features or Syntax** None mentioned in this benchmark. **Other Alternatives** There are other alternatives for reversing an array, such as: 1. **Using `slice()`, `concat()`, and `reverse()`**: This approach creates a new array by concatenating the reversed elements. 2. **Using a loop**: A simple loop can be used to reverse an array in place. 3. **Using `reduce()`**: An array can be reversed using the `reduce()` method, which is less common than other methods. **Benchmark Preparation Code** The provided JSON includes two scripts: 1. `test = [\"a\", \"b\", \"c\", \"d\", \"e\"];`: Creates an array of strings. 2. No HTML preparation code is provided. **Latest Benchmark Result** The latest benchmark result shows the performance of both test cases on a specific browser (Chrome 127) and device platform (Desktop). The results are: * ES Reverse / in place: 3,859,801 executions per second * ES Map: 1,483,106.125 executions per second These results suggest that in-place reversal (ES Reverse) is faster than creating a new array with `map()` (ES Map) on this specific hardware and software configuration.
Related benchmarks:
Array.from() vs new Array() performance...
Array.from() vs new Array() vs [..Array()]
Array.from() vs new Array() - map
Array.from() vs new Array().map()
Math.max() vs .map().sort().reverse()
Comments
Confirm delete:
Do you really want to delete benchmark?