Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array vs int16array
(version: 0)
Comparing performance of:
array reverse vs typedArray reverse vs array i/o vs typedArray i/o
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var a = [...Array(10000)].map(_ => Math.random(1000000)); var ta = (new Int16Array(10000)).map(_ => Math.random(1000000));
Tests:
array reverse
a.reverse();
typedArray reverse
ta.reverse();
array i/o
for (let i = 0; i < 10000; ++i) a[i] = a[i] + 1;
typedArray i/o
for (let i = 0; i < 10000; ++i) ta[i] = ta[i] + 1;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
array reverse
typedArray reverse
array i/o
typedArray i/o
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array reverse
200955.7 Ops/sec
typedArray reverse
344924.1 Ops/sec
array i/o
57889.2 Ops/sec
typedArray i/o
179769.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, providing insights into the performance differences between various approaches. **Benchmark Definition JSON** The provided Benchmark Definition JSON defines a benchmark comparing `Array` and `Int16Array`. The script preparation code generates two arrays of size 10,000 with random integers. The HTML preparation code is empty. Here's what's being tested: 1. **Array vs Int16Array**: The benchmark compares the performance of accessing elements in an ordinary `Array` (`a`) versus a typed array (`Int16Array`, `ta`). Typed arrays are designed to store specific data types, such as integers or floats, and provide better performance and memory efficiency. **Comparison options** Two approaches are compared: 1. **Array access**: The benchmark measures the time it takes to reverse an ordinary `Array` using the `reverse()` method. 2. **Typed Array access**: The benchmark measures the time it takes to perform similar operations on a typed array (`Int16Array`) using the same `reverse()` method. **Pros and cons of each approach** 1. **Array access**: * Pros: Easier to implement, works with any type of data. * Cons: Slower performance due to dynamic typing and potential overhead from JavaScript's garbage collection. 2. **Typed Array access**: * Pros: Faster performance, reduced memory usage, and better cache locality. * Cons: Requires explicit type definitions, may be less flexible. **Library** The `getRandomInt` function is a simple utility function that generates random integers within a specified range. It's not a library per se, but rather a helper function used to populate the arrays. **Special JavaScript feature or syntax** None are mentioned in the provided code snippet. However, it's worth noting that MeasureThat.net may use other features like `Promise` or `async/await` for benchmarking purposes, which would require additional context. **Other alternatives** If you were to rewrite this benchmark with different approaches, some options might include: 1. Using `BigInt` instead of integers: This could provide better performance for very large numbers. 2. Comparing other data structures, such as `Set` or `Map`, against `Array`. 3. Investigating the impact of array length and density on performance. Keep in mind that the best approach will depend on your specific use case and requirements.
Related benchmarks:
Get max from an array of numbers (Math.max vs. iteration)
Get max from an array of numbers (Math.max vs. iteration) V3
Math.random vs Crypto.getRandomValues for 10k values
new Array() vs Array.from() with random data
Array.find vs. Map.get 300
Comments
Confirm delete:
Do you really want to delete benchmark?