Implement micro-benchmark for Proxy call and construct

Bug: v8:6558, v8:6557
Change-Id: Ife58f78d00bfd53d6b904e838cbd028f039945b4
Reviewed-on: https://chromium-review.googlesource.com/567501
Commit-Queue: Maya Lekova <mslekova@google.com>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46588}
This commit is contained in:
Maya Lekova 2017-07-12 14:58:37 +02:00 committed by Commit Bot
parent cad3c5a166
commit 7280d03b98

View File

@ -69,3 +69,85 @@ newBenchmark("ProxyConstructorWithProxy", {
return (typeof result == 'function'); return (typeof result == 'function');
} }
}); });
// ----------------------------------------------------------------------------
const SOME_NUMBER = 42;
const SOME_OTHER_NUMBER = 1337;
const ITERATIONS = 1000;
newBenchmark("CallProxyWithoutTrap", {
setup() {
const target = () => { return SOME_NUMBER; };
p = new Proxy(target, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p();
}
},
teardown() {
return (result === SOME_NUMBER);
}
});
// ----------------------------------------------------------------------------
newBenchmark("CallProxyWithTrap", {
setup() {
const target = () => { return SOME_NUMBER; };
p = new Proxy(target, {
apply: function(target, thisArg, argumentsList) {
return SOME_OTHER_NUMBER;
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
p();
}
},
teardown() {
return (result === SOME_OTHER_NUMBER);
}
});
var instance;
class MyClass {
};
// ----------------------------------------------------------------------------
newBenchmark("ConstructProxyWithoutTrap", {
setup() {
p = new Proxy(MyClass, {});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
instance = new p();
}
},
teardown() {
return instance instanceof MyClass;
}
});
// ----------------------------------------------------------------------------
newBenchmark("ConstructProxyWithTrap", {
setup() {
p = new Proxy(Object, {
construct: function(target, argumentsList, newTarget) {
return new MyClass;
}
});
},
run() {
for(var i = 0; i < ITERATIONS; i++) {
instance = new p();
}
},
teardown() {
return instance instanceof MyClass;
}
});