Implement microbenchmark for has-in idiom
Bug: v8:6557 Change-Id: Ia858c87a602a37e70d9df61c7225eda10e566258 Reviewed-on: https://chromium-review.googlesource.com/663727 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Maya Lekova <mslekova@google.com> Cr-Commit-Position: refs/heads/master@{#47990}
This commit is contained in:
parent
721f94ad99
commit
26d299755e
@ -30,7 +30,8 @@
|
||||
{"name": "SetIndexWithoutTrap"},
|
||||
{"name": "SetIndexWithTrap"},
|
||||
{"name": "SetSymbolWithoutTrap"},
|
||||
{"name": "SetSymbolWithTrap"}
|
||||
{"name": "SetSymbolWithTrap"},
|
||||
{"name": "HasInIdiom"}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -463,3 +463,43 @@ newBenchmark("SetSymbolWithTrap", {
|
||||
return value === SOME_OTHER_NUMBER;
|
||||
}
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
var obj20prop = {};
|
||||
var measured;
|
||||
|
||||
newBenchmark("HasInIdiom", {
|
||||
setup() {
|
||||
for (var i = 0; i < 20; ++i) {
|
||||
obj20prop['prop' + i] = SOME_NUMBER;
|
||||
}
|
||||
p = new Proxy(obj20prop, {
|
||||
has: function(target, propertyKey) {
|
||||
return true;
|
||||
},
|
||||
get: function(target, propertyKey, receiver) {
|
||||
if (typeof propertyKey == 'string' && propertyKey.match('prop'))
|
||||
return SOME_NUMBER;
|
||||
else
|
||||
return Reflect.get(target, propertyKey, receiver);
|
||||
},
|
||||
});
|
||||
measured = function measured(o) {
|
||||
var result = 0;
|
||||
for (var x in o) {
|
||||
if (Object.prototype.hasOwnProperty(o, x)) {
|
||||
var v = o[x];
|
||||
result += v;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
},
|
||||
run() {
|
||||
result = measured(p);
|
||||
},
|
||||
teardown() {
|
||||
return result === 20 * SOME_NUMBER;
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user