function suffle(arr) {
const len = arr.length;
for (let i = len - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
var obj = [];
for (let i = 0; i < 100; i++) {
obj.push({
[i]: i,
[i + 1]: i + 1,
[i + 2]: i + 2,
[i + 3]: i + 3
});
}
var num = [];
for (let i = 0; i < 100; i++) {
num.push(i);
}
suffle(obj);
suffle(num);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Large Object Contents | |
Number Content |
Test name | Executions per second |
---|---|
Large Object Contents | 36802.2 Ops/sec |
Number Content | 36799.9 Ops/sec |
Let's break down the provided JSON and benchmark preparation code to understand what is being tested on MeasureThat.net.
Benchmark Definition JSON
The benchmark definition represents a JavaScript function that shuffles an array of objects with multiple properties. The function, suffle
, takes an array as input, iterates through it in reverse order, and swaps each element with a randomly selected element from the remaining unswapped portion of the array.
Script Preparation Code
The script preparation code is a JavaScript function that creates two arrays: obj
and num
. The obj
array contains 100 objects with four properties each ( [i]
, [i+1]
, [i+2]
, and [i+3]
) where the property values are equal to the index i
. The num
array contains 100 integers from 0 to 99.
Html Preparation Code
The html preparation code is currently empty, which means that no HTML is generated or modified before running the benchmark.
Individual Test Cases
There are two test cases:
suffle
function on the obj
array.suffle
function on the num
array.Options Compared
The benchmark compares the performance of shuffling arrays with different properties (object vs. integer).
Pros and Cons of Each Approach
Cons:
Library Used
There is no explicit library used in this benchmark. The suffle
function uses only built-in JavaScript features and data structures (arrays and objects).
Special JS Feature or Syntax
This benchmark does not use any special JavaScript features or syntax that would impact performance. However, it's worth noting that the use of arrays and object properties can affect performance depending on the browser implementation.
Other Considerations
When shuffling arrays, consider the following factors:
Alternatives to MeasureThat.net:
Note: These alternatives may offer more features, flexibility, and customization options than MeasureThat.net.