diff --git a/test/js-perf-test/JSTests.json b/test/js-perf-test/JSTests.json index 763d621e5f..a9cd6eba78 100644 --- a/test/js-perf-test/JSTests.json +++ b/test/js-perf-test/JSTests.json @@ -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"} ] }, { diff --git a/test/js-perf-test/Proxies/proxies.js b/test/js-perf-test/Proxies/proxies.js index c93c2c35b8..6bb56bd97d 100644 --- a/test/js-perf-test/Proxies/proxies.js +++ b/test/js-perf-test/Proxies/proxies.js @@ -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; + } +});