Commit 753d987a authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

Add micro-benchmark for Proxy set property

Add additional tests for Proxy get and has property.

Bug: v8:6560, v8:6557
Change-Id: I56360c230b03a16425f4068d8023f90b3164eebb
Reviewed-on: https://chromium-review.googlesource.com/607889
Commit-Queue: Maya Lekova <mslekova@google.com>
Reviewed-by: 's avatarFranziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47290}
parent a17ed358
......@@ -15,18 +15,22 @@
"resources": ["proxies.js"],
"results_regexp": "^%s\\-Proxies\\(Score\\): (.+)$",
"tests": [
{"name": "ProxyConstructorWithArrowFunc"},
{"name": "ProxyConstructorWithClass"},
{"name": "ProxyConstructorWithObject"},
{"name": "ProxyConstructorWithProxy"},
{"name": "CallProxyWithoutTrap"},
{"name": "CallProxyWithTrap"},
{"name": "ConstructProxyWithoutTrap"},
{"name": "ConstructProxyWithTrap"},
{"name": "GetPropertyOfProxyWithoutTrap"},
{"name": "GetPropertyOfProxyWithTrap"},
{"name": "HasOnProxyWithoutTrap"},
{"name": "HasOnProxyWithTrap"}
{"name": "GetStringWithoutTrap"},
{"name": "GetStringWithTrap"},
{"name": "GetIndexWithoutTrap"},
{"name": "GetIndexWithTrap"},
{"name": "GetSymbolWithoutTrap"},
{"name": "GetSymbolWithTrap"},
{"name": "HasStringWithoutTrap"},
{"name": "HasStringWithTrap"},
{"name": "HasSymbolWithoutTrap"},
{"name": "HasSymbolWithTrap"},
{"name": "SetStringWithoutTrap"},
{"name": "SetStringWithTrap"},
{"name": "SetIndexWithoutTrap"},
{"name": "SetIndexWithTrap"},
{"name": "SetSymbolWithoutTrap"},
{"name": "SetSymbolWithTrap"}
]
},
{
......
......@@ -159,7 +159,7 @@ obj = {
}
let value;
newBenchmark("GetPropertyOfProxyWithoutTrap", {
newBenchmark("GetStringWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
......@@ -175,7 +175,7 @@ newBenchmark("GetPropertyOfProxyWithoutTrap", {
// ----------------------------------------------------------------------------
newBenchmark("GetPropertyOfProxyWithTrap", {
newBenchmark("GetStringWithTrap", {
setup() {
p = new Proxy(obj, {
get: function(target, propertyKey, receiver) {
......@@ -195,9 +195,86 @@ newBenchmark("GetPropertyOfProxyWithTrap", {
// ----------------------------------------------------------------------------
obj = [SOME_NUMBER];
newBenchmark("GetIndexWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = p[0];
}
},
teardown() {
return value === SOME_NUMBER;
}
});
// ----------------------------------------------------------------------------
newBenchmark("GetIndexWithTrap", {
setup() {
p = new Proxy(obj, {
get: function(target, propertyKey, receiver) {
return SOME_OTHER_NUMBER;
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = p[0];
}
},
teardown() {
return value === SOME_OTHER_NUMBER;
}
});
// ----------------------------------------------------------------------------
var symbol = Symbol();
obj[symbol] = SOME_NUMBER;
newBenchmark("GetSymbolWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = p[symbol];
}
},
teardown() {
return value === SOME_NUMBER;
}
});
// ----------------------------------------------------------------------------
newBenchmark("GetSymbolWithTrap", {
setup() {
p = new Proxy(obj, {
get: function(target, propertyKey, receiver) {
return SOME_OTHER_NUMBER;
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = p[symbol];
}
},
teardown() {
return value === SOME_OTHER_NUMBER;
}
});
// ----------------------------------------------------------------------------
obj = {};
newBenchmark("HasOnProxyWithoutTrap", {
newBenchmark("HasStringWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
......@@ -210,9 +287,10 @@ newBenchmark("HasOnProxyWithoutTrap", {
return value === true;
}
});
// ----------------------------------------------------------------------------
newBenchmark("HasOnProxyWithTrap", {
newBenchmark("HasStringWithTrap", {
setup() {
p = new Proxy(obj, {
has: function(target, propertyKey) {
......@@ -229,3 +307,159 @@ newBenchmark("HasOnProxyWithTrap", {
return value === true;
}
});
// ----------------------------------------------------------------------------
obj[symbol] = SOME_NUMBER;
newBenchmark("HasSymbolWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = (symbol in p);
}
},
teardown() {
return value === true;
}
});
// ----------------------------------------------------------------------------
newBenchmark("HasSymbolWithTrap", {
setup() {
p = new Proxy(obj, {
has: function(target, propertyKey) {
return true;
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
value = (symbol in p);
}
},
teardown() {
return value === true;
}
});
// ----------------------------------------------------------------------------
obj = {
prop: undefined
}
value = SOME_NUMBER;
newBenchmark("SetStringWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p.prop = value;
}
},
teardown() {
return value === SOME_NUMBER;
}
});
// ----------------------------------------------------------------------------
newBenchmark("SetStringWithTrap", {
setup() {
p = new Proxy(obj, {
set: function(target, propertyKey, value, receiver) {
target[propertyKey] = SOME_OTHER_NUMBER
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p.prop = value;
}
},
teardown() {
return value === SOME_OTHER_NUMBER;
}
});
// ----------------------------------------------------------------------------
obj = [undefined];
value = SOME_NUMBER;
newBenchmark("SetIndexWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p[0] = value;
}
},
teardown() {
return value === SOME_NUMBER;
}
});
// ----------------------------------------------------------------------------
newBenchmark("SetIndexWithTrap", {
setup() {
p = new Proxy(obj, {
set: function(target, propertyKey, value, receiver) {
target[propertyKey] = SOME_OTHER_NUMBER
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p[0] = value;
}
},
teardown() {
return value === SOME_OTHER_NUMBER;
}
});
// ----------------------------------------------------------------------------
obj[symbol] = undefined;
value = SOME_NUMBER;
newBenchmark("SetSymbolWithoutTrap", {
setup() {
p = new Proxy(obj, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p[symbol] = value;
}
},
teardown() {
return value === SOME_NUMBER;
}
});
// ----------------------------------------------------------------------------
newBenchmark("SetSymbolWithTrap", {
setup() {
p = new Proxy(obj, {
set: function(target, propertyKey, value, receiver) {
target[propertyKey] = SOME_OTHER_NUMBER
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p[symbol] = value;
}
},
teardown() {
return value === SOME_OTHER_NUMBER;
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment