function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
var a = [Array(10000)].map(_ => Math.random(1000000));
var ta = (new Float32Array(10000)).map(_ => Math.random(1000000));
a.sort();
ta.sort();
for (let i = 0, n = 10000 - 2; i < n; ++i) {
a[i] = a[i] * a[i] + a[i + 1] / 2 + a[i + 2];
}
for (let i = 0, n = 10000 - 2; i < n; ++i) {
ta[i] = ta[i] * ta[i] + ta[i + 1] / 2 + ta[i + 2];
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
array sort | |
typedArray sort | |
array i/o | |
typedArray i/o |
Test name | Executions per second |
---|---|
array sort | 601.0 Ops/sec |
typedArray sort | 14473.9 Ops/sec |
array i/o | 215.3 Ops/sec |
typedArray i/o | 217.4 Ops/sec |
Benchmark Overview
MeasureThat.net is a platform that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark definition and its corresponding test cases.
The main goal of this benchmark is to compare the performance of array and Float32Array (a typed array) in various operations, such as sorting and input/output calculations.
Options Compared
In the provided benchmark definition, two options are compared:
sort()
method.sort()
method on the typed array.These two tests aim to measure the performance difference between JavaScript's built-in arrays and typed arrays in terms of sorting efficiency.
Pros and Cons
Library Usage
In the provided benchmark definition, no external libraries are explicitly mentioned. However, it's worth noting that MeasureThat.net likely relies on some internal libraries or frameworks to manage the benchmarking process.
Special JS Features or Syntax
The benchmark definition uses the following special JavaScript features:
var a = [...Array(10000)].map(_ => Math.random(1000000));
, which creates an array of 10,000 elements using the spread operator.a[i] = a[i] * a[i] + a[i + 1] / 2 + a[i + 2];
and similar places, which define small, anonymous functions.Alternatives
If you're interested in exploring alternative approaches or implementing your own benchmarking framework, here are some options to consider:
Keep in mind that MeasureThat.net is designed to provide an easy-to-use interface for users who want to create and run JavaScript microbenchmarks. If you're interested in exploring more advanced or specialized benchmarking techniques, you may want to consider using a dedicated benchmarking library or framework.