Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
var array = [1,2,3];
(version: 0)
var array = [1,2,3];
Comparing performance of:
var z = array.at(-1); vs selectedAssetKeys.slice(-1)?.[0]
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
var z = array.at(-1);
var array = [1,2,3]; var aaa = array.at(-1);
selectedAssetKeys.slice(-1)?.[0]
var array = [1,2,3]; var bbb = array.slice(-1)?.[0]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
var z = array.at(-1);
selectedAssetKeys.slice(-1)?.[0]
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; rv:125.0) Gecko/20100101 Firefox/125.0
Browser/OS:
Firefox 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
var z = array.at(-1);
149524288.0 Ops/sec
selectedAssetKeys.slice(-1)?.[0]
54720648.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's tested in the provided JSON benchmark. **Benchmark Overview** The benchmark consists of two test cases, each measuring the performance of JavaScript arrays. The benchmarks are designed to compare the execution speed of different array manipulation methods. **Test Cases** 1. **`var z = array.at(-1);`** * This test case measures the performance of accessing the last element of an array using the `at()` method. 2. **`selectedAssetKeys.slice(-1)?.[0]`** * This test case measures the performance of slicing an array from the end and then accessing the first element, or a null value if the slice is empty. **Comparison Options** The benchmark compares two approaches: 1. `at()` method 2. `slice()` method with optional chaining (`?.[0]`) **Pros and Cons** * **`at()` method**: + Pros: More concise and expressive, especially for accessing elements from the end of an array. + Cons: May be slower than `slice()` due to its overhead, although this is not significant in most cases. The `at()` method is also less widely supported across older browsers and Node.js versions. * **`slice()` method with optional chaining (`?.[0]`)**: + Pros: Widely supported across modern browsers and Node.js versions, making it a safer choice for cross-browser compatibility. + Cons: More verbose than the `at()` method, which may make it less readable. **Library Usage** There is no explicit library usage in this benchmark. However, note that some browsers (e.g., Chrome) have built-in support for the `at()` method since version 75, while others (e.g., Firefox) have implemented it more recently (version 125). **Special JS Features or Syntax** The test cases do not use any special JavaScript features or syntax beyond what is standard in modern JavaScript. **Other Alternatives** If you need to measure the performance of other array manipulation methods, consider alternatives like: 1. `indexOf()` and `slice()` 2. `map()` and `reduce()` 3. Using Array.prototype functions like `forEach()`, `some()`, or `every()` When preparing benchmarks, keep in mind that the choice of comparison options depends on your specific use case, target audience, and performance characteristics. If you'd like to discuss more about benchmarking JavaScript or have further questions, feel free to ask!
Related benchmarks:
array push
teststest
Javascript Push
new array vs array length
array.length = 0 vs []
Comments
Confirm delete:
Do you really want to delete benchmark?