var objs = [];
var proxProp = [];
var proxDyn = [];
var proxEval = [];
var proxFunc = [];
var count = 1000;
var a, b, c;
class ProxProp {
constructor(data) { this.data = data }
get a() { return this.data.a; }
get b() { return this.data.b; }
get c() { return this.data.c; }
set a(v) { this.data.a = v; }
set b(v) { this.data.b = v; }
set c(v) { this.data.c = v; }
}
const ProxEval = eval(`class ProxEval {
constructor(data) { this.data = data }
get a() { return this.data.a; }
get b() { return this.data.b; }
get c() { return this.data.c; }
set a(v) { this.data.a = v; }
set b(v) { this.data.b = v; }
set c(v) { this.data.c = v; }
};
ProxEval;
`);
const ProxFunc = new Function(`return class ProxFunc {
constructor(data) { this.data = data }
get a() { return this.data.a; }
get b() { return this.data.b; }
get c() { return this.data.c; }
set a(v) { this.data.a = v; }
set b(v) { this.data.b = v; }
set c(v) { this.data.c = v; }
};
`);
class ProxDyn {
constructor(data) { this.data = data }
}
["a", "b", "c"].forEach(n=> Object.defineProperty(ProxDyn.prototype, n, {
get() { return this.data[n]; },
set(v) { this.data[n] = v; },
}));
for (let i = 0; i < count; i++) {
const obj = { a: Math.random(), b: new Date, c: Date.now().toString() };
objs.push(obj);
proxProp.push(new ProxProp(obj));
proxDyn.push(new ProxDyn(obj));
proxEval.push(new ProxEval(obj));
proxFunc.push(new ProxFunc(obj));
}
for (let i = 0; i < proxEval.length; i++) {
const obj = proxEval[i];
a = obj.a;
b = obj.b;
c = obj.c;
}
for (let i = 0; i < proxProp.length; i++) {
const obj = proxProp[i];
a = obj.a;
b = obj.b;
c = obj.c;
}
for (let i = 0; i < proxDyn.length; i++) {
const obj = proxDyn[i];
a = obj.a;
b = obj.b;
c = obj.c;
}
for (let i = 0; i < objs.length; i++) {
const obj = objs[i];
a = obj.a;
b = obj.b;
c = obj.c;
}
for (let i = 0; i < objs.length; i++) {
const obj = objs[i];
}
for (let i = 0; i < proxFunc.length; i++) {
const obj = proxFunc[i];
a = obj.a;
b = obj.b;
c = obj.c;
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Get generated property with eval | |
Get property | |
Get dynamic property | |
Get field | |
Nothing | |
Get generated property with Function ctor |
Test name | Executions per second |
---|---|
Get generated property with eval | 3741.8 Ops/sec |
Get property | 3745.4 Ops/sec |
Get dynamic property | 3721.2 Ops/sec |
Get field | 3787.8 Ops/sec |
Nothing | 12450.9 Ops/sec |
Get generated property with Function ctor | 3806.3 Ops/sec |
Let's dive into the world of microbenchmarks and explore what's being tested in this specific benchmark.
Benchmark Overview
The provided JSON represents a JavaScript microbenchmarking test case on MeasureThat.net. The test measures the performance of different approaches to access properties of objects. There are six individual test cases, each with its own unique characteristics.
Test Cases
obj.a
).obj['a']
) to access the property.eval
function to create a new object with a property.What's being tested?
The primary focus of this benchmark is to measure the performance differences between various approaches to access properties on objects. The tests aim to evaluate:
eval
Performance Insights
From the provided benchmark results, we can observe the following:
eval
results in slower performance compared to direct property access or bracket notation.Overall, this benchmark provides valuable insights into the performance characteristics of different approaches to accessing properties on objects in JavaScript.