Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testing shift vs splice perf
(version: 0)
Comparing performance of:
splice vs shift
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
splice
const things = new Array(1000000) const a = things.slice(1)
shift
const things = new Array(1000000) const b = things.shift(1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
splice
shift
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
splice
148.4 Ops/sec
shift
291.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided JSON represents two test cases for measuring the performance difference between using `Array.shift()` and `Array.splice()`. These methods are used to remove elements from an array. **What is being tested?** Two individual test cases are compared: 1. **`splice`**: This test case uses `Array.prototype.splice()` to create a copy of the original array (`things`) and then removes the first element from the copied array. 2. **`shift`**: This test case uses `Array.prototype.shift()` to remove the first element directly from the original array (`things`). **Options compared** The two methods being tested are: * `splice()`: This method creates a new array with the elements shifted down by one position, and removes the specified element(s) from the end of the array. It returns an array of removed elements. * `shift()`: This method removes the first element from the array and returns it. **Pros and Cons** ### Splice() Pros: * Allows for more flexibility in removing elements from the array (e.g., removing multiple elements, replacing elements). * Can be used to create a new array with modified elements. Cons: * Creates a new array, which can be memory-intensive. * Returns an array of removed elements, which can add overhead. ### Shift() Pros: * More efficient than `splice()` since it only removes the first element without creating a new array. * Returns the removed element directly. Cons: * Can only remove one element at a time from the beginning of the array. * Does not return any modified arrays. **Library usage** There is no library being used in these test cases. The `Array.prototype` methods are being tested natively. **Special JS feature or syntax** None mentioned, but it's worth noting that some browsers may have specific optimizations for these methods (e.g., Chrome has a optimized implementation of `shift()` and `splice()`). **Other alternatives** If you wanted to test other array manipulation methods, you could consider using: * `Array.prototype.slice()`: Similar to `splice()`, but creates a shallow copy of the array. * `Array.prototype.unshift()`: Adds elements to the beginning of the array. * `Array.prototype.pop()`: Removes and returns the last element from the end of the array. However, it's worth noting that these alternatives may not provide the same level of performance as the native methods being tested.
Related benchmarks:
Splice vs shift to remove at beginning of array (fixed from slice)
Splice vs Shift to remove from the beginning
Splice vs Shift perf
Empty array: Splice vs Shift
Comments
Confirm delete:
Do you really want to delete benchmark?