function generateTestArray() {
const result = [];
for (let i = 0; i < 1000000; ++i) {
result.push({
a: i,
b: i / 2,
r: 0,
});
}
return result;
}
var array = generateTestArray();
array.forEach((x) => {
x.r = x.a + x.b;
});
for(const x of array) {
x.r = x.a + x.b;
}
const r = [];
for(const {a, b} of array) {
r.push(a + b);
}
array.map(x => x.a + x.b)
array.map(({a,b}) => a + b)
const r = new Array(array.length);
for (let i = 0; i < array.length; ++i) {
r[i] = array[i].a + array[i].b;
}
array.reduce((p, x) => p + x.a + x.b, 0);
array.reduce((p, {a,b}) => p + a + b, 0);
let r = 0;
for (const x of array) {
r += x.a + x.b;
}
let r = 0;
for (const {a,b} of array) {
r += a + b;
}
array.forEach((_, i) => {
array[i].r = array[i].a + array[i].b;
});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
.forEach | |
for..of | |
for..of (destructuring) | |
.map | |
.map (destructuring) | |
.for (init array) | |
.reduce | |
.reduce (destructuring) | |
for..of (reduce) | |
for..of (reduce) (destructuring) | |
forEach index |
Test name | Executions per second |
---|---|
.forEach | 75.9 Ops/sec |
for..of | 76.2 Ops/sec |
for..of (destructuring) | 27.3 Ops/sec |
.map | 23.1 Ops/sec |
.map (destructuring) | 21.6 Ops/sec |
.for (init array) | 6.6 Ops/sec |
.reduce | 64.2 Ops/sec |
.reduce (destructuring) | 69.2 Ops/sec |
for..of (reduce) | 77.3 Ops/sec |
for..of (reduce) (destructuring) | 77.2 Ops/sec |
forEach index | 6.4 Ops/sec |
I'm ready to help! You provided a JSON-like string with an array of objects, each representing data from user agent strings. What would you like me to extract or do with this data?