function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// 31 bit +ve integer smi
var randSmi = () => crypto.getRandomValues(new Uint32Array(1))[0] & 0x7fffffff;
// 6-7 char alphanumeric string
var randStr = () => randSmi().toString(36);
var numEntries = 64;
var numRounds = 100 * numEntries;
var strObj = {};
var strObjKeys = Array(numEntries);
var numObj = {};
var numObjKeys = Array(numEntries);
var strSeqObj = {};
var strSeqObjKeys = Array(numEntries);
var numSeqObj = {};
var numSeqObjKeys = Array(numEntries);
for (let i = 0; i < numEntries; i++) {
let strKey = `k${randStr()}`, numKey = randSmi();
let strSeqKey = `k${i}`, numSeqKey = i;
strObj[strKey] = i;
strObjKeys[i] = strKey;
numObj[numKey] = i;
numObjKeys[i] = numKey;
strSeqObj[strSeqKey] = i;
strSeqObjKeys[i] = strSeqKey;
numSeqObj[numSeqKey] = i;
numSeqObjKeys[i] = numSeqKey;
}
Object.freeze(strObj);
Object.freeze(numObj);
Object.freeze(strSeqObj);
Object.freeze(numSeqObj);
var strMap = new Map(Object.entries(strObj));
var numMap = new Map(Object.entries(numObj));
var strSeqMap = new Map(Object.entries(strSeqObj));
var numSeqMap = new Map(Object.entries(numSeqObj));
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += strObj[strObjKeys[Math.random() * numEntries | 0]];
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += numObj[numObjKeys[Math.random() * numEntries | 0]];
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += strSeqObj[strSeqObjKeys[Math.random() * numEntries | 0]];
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += numSeqObj[numSeqObjKeys[Math.random() * numEntries | 0]];
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += strMap.get(strObjKeys[Math.random() * numEntries | 0]);
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += numMap.get(numObjKeys[Math.random() * numEntries | 0]);
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += strSeqMap.get(strSeqObjKeys[Math.random() * numEntries | 0]);
}
let total = 0;
for (let i = 0; i < numRounds; i++) {
total += numSeqMap.get(numSeqObjKeys[Math.random() * numEntries | 0]);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object random string keys | |
Object random numeric smi keys | |
Object sequential string keys | |
Object sequential numeric smi keys | |
Map random string keys | |
Map random numeric smi keys | |
Map sequential string keys | |
Map sequential numeric smi keys |
Test name | Executions per second |
---|---|
Object random string keys | 1819.6 Ops/sec |
Object random numeric smi keys | 1943.9 Ops/sec |
Object sequential string keys | 2391.1 Ops/sec |
Object sequential numeric smi keys | 8006.1 Ops/sec |
Map random string keys | 1742.2 Ops/sec |
Map random numeric smi keys | 4685.1 Ops/sec |
Map sequential string keys | 2098.9 Ops/sec |
Map sequential numeric smi keys | 5636.5 Ops/sec |
It seems like you're sharing some benchmark results from a Firefox Mobile test. Let's dive into the details.
The tests seem to be comparing the performance of different map operations:
The results show the average number of executions per second (ExecutionsPerSecond) for each test on different devices running Firefox Mobile 99.
Based on these results, we can observe:
Overall, it seems that: