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 @@ ...@@ -15,18 +15,22 @@
"resources": ["proxies.js"], "resources": ["proxies.js"],
"results_regexp": "^%s\\-Proxies\\(Score\\): (.+)$", "results_regexp": "^%s\\-Proxies\\(Score\\): (.+)$",
"tests": [ "tests": [
{"name": "ProxyConstructorWithArrowFunc"}, {"name": "GetStringWithoutTrap"},
{"name": "ProxyConstructorWithClass"}, {"name": "GetStringWithTrap"},
{"name": "ProxyConstructorWithObject"}, {"name": "GetIndexWithoutTrap"},
{"name": "ProxyConstructorWithProxy"}, {"name": "GetIndexWithTrap"},
{"name": "CallProxyWithoutTrap"}, {"name": "GetSymbolWithoutTrap"},
{"name": "CallProxyWithTrap"}, {"name": "GetSymbolWithTrap"},
{"name": "ConstructProxyWithoutTrap"}, {"name": "HasStringWithoutTrap"},
{"name": "ConstructProxyWithTrap"}, {"name": "HasStringWithTrap"},
{"name": "GetPropertyOfProxyWithoutTrap"}, {"name": "HasSymbolWithoutTrap"},
{"name": "GetPropertyOfProxyWithTrap"}, {"name": "HasSymbolWithTrap"},
{"name": "HasOnProxyWithoutTrap"}, {"name": "SetStringWithoutTrap"},
{"name": "HasOnProxyWithTrap"} {"name": "SetStringWithTrap"},
{"name": "SetIndexWithoutTrap"},
{"name": "SetIndexWithTrap"},
{"name": "SetSymbolWithoutTrap"},
{"name": "SetSymbolWithTrap"}
] ]
}, },
{ {
......
...@@ -159,7 +159,7 @@ obj = { ...@@ -159,7 +159,7 @@ obj = {
} }
let value; let value;
newBenchmark("GetPropertyOfProxyWithoutTrap", { newBenchmark("GetStringWithoutTrap", {
setup() { setup() {
p = new Proxy(obj, {}); p = new Proxy(obj, {});
}, },
...@@ -175,7 +175,7 @@ newBenchmark("GetPropertyOfProxyWithoutTrap", { ...@@ -175,7 +175,7 @@ newBenchmark("GetPropertyOfProxyWithoutTrap", {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
newBenchmark("GetPropertyOfProxyWithTrap", { newBenchmark("GetStringWithTrap", {
setup() { setup() {
p = new Proxy(obj, { p = new Proxy(obj, {
get: function(target, propertyKey, receiver) { get: function(target, propertyKey, receiver) {
...@@ -195,9 +195,86 @@ newBenchmark("GetPropertyOfProxyWithTrap", { ...@@ -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 = {}; obj = {};
newBenchmark("HasOnProxyWithoutTrap", { newBenchmark("HasStringWithoutTrap", {
setup() { setup() {
p = new Proxy(obj, {}); p = new Proxy(obj, {});
}, },
...@@ -210,9 +287,10 @@ newBenchmark("HasOnProxyWithoutTrap", { ...@@ -210,9 +287,10 @@ newBenchmark("HasOnProxyWithoutTrap", {
return value === true; return value === true;
} }
}); });
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
newBenchmark("HasOnProxyWithTrap", { newBenchmark("HasStringWithTrap", {
setup() { setup() {
p = new Proxy(obj, { p = new Proxy(obj, {
has: function(target, propertyKey) { has: function(target, propertyKey) {
...@@ -229,3 +307,159 @@ newBenchmark("HasOnProxyWithTrap", { ...@@ -229,3 +307,159 @@ newBenchmark("HasOnProxyWithTrap", {
return value === true; 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