var array = Array(100).map((el, index) => index);
let i = 10000;
while(i>0) {
const t1 = array.splice()
i--;
}
let i = 10000;
while(i>0) {
const t1 = [array];
i--;
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
splice | |
deconstruct |
Test name | Executions per second |
---|---|
splice | 853.6 Ops/sec |
deconstruct | 108.3 Ops/sec |
Let's break down the benchmark and its test cases.
What is tested:
The provided benchmark tests two different approaches to removing elements from an array in JavaScript:
splice()
function returns the removed elements as an array.The benchmark measures the performance of these two approaches in terms of how many executions per second on a given test case with a large array of 100 elements.
Options compared:
Other considerations:
Library usage:
None of the test cases uses any external libraries. Both approaches use built-in JavaScript methods: splice()
and destructuring assignment.
Special JS feature or syntax:
The benchmark uses a simple example that demonstrates the basic behavior of both approaches. There are no special features or syntax used, such as async/await, classes, or functional programming concepts.
Other alternatives:
If you want to test other approaches for removing elements from an array in JavaScript, some alternatives could include:
filter()
method with a callback functionmap()
method with a callback function and then using slice()
to remove elementsKeep in mind that these alternatives may have different performance characteristics and trade-offs compared to the approaches tested in this benchmark.