Commit 2318facd authored by ishell's avatar ishell Committed by Commit bot

[js-perf-test] Fix JSTests/PropertyQueries microbenchmark.

1) Create fast objects so that they stay fast after creation.
2) Run combination "test_function vs {test_objects}" as a benchmark during 1 second.

This CL changes benchmark's base score.

Review-Url: https://codereview.chromium.org/1988673002
Cr-Commit-Position: refs/heads/master@{#36277}
parent 8e303dd0
...@@ -3,12 +3,17 @@ ...@@ -3,12 +3,17 @@
// found in the LICENSE file. // found in the LICENSE file.
function ObjectWithKeys(count, keyOffset = 0, keyGen) { function ObjectWithKeys(count, keyOffset = 0, keyGen) {
var o = {}; var body = "";
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var key = keyGen(i + keyOffset); var key = keyGen(i + keyOffset);
o[key] = "value"; if (typeof key === "string") {
body += `this.${key} = 0\n`;
} else {
body += `this[${key}] = 0\n`;
}
} }
return o; var f = new Function(body);
return new f();
} }
function ObjectWithProperties(count, keyOffset) { function ObjectWithProperties(count, keyOffset) {
...@@ -166,7 +171,7 @@ var TestData = []; ...@@ -166,7 +171,7 @@ var TestData = [];
var proto_mode = cachable ? "" : "-with-slow-proto"; var proto_mode = cachable ? "" : "-with-slow-proto";
var name = `${obj_mode}-obj${proto_mode}`; var name = `${obj_mode}-obj${proto_mode}`;
var objects = []; var objects = [];
[10, 50, 100, 200, 500, 1000].forEach((prop_count) => { [10, 50, 100, 200, 500].forEach((prop_count) => {
// Create object with prop_count properties and prop_count elements. // Create object with prop_count properties and prop_count elements.
obj = ObjectWithProtoKeys(5, prop_count * 2, cachable, obj = ObjectWithProtoKeys(5, prop_count * 2, cachable,
ObjectWithMixedKeys); ObjectWithMixedKeys);
...@@ -190,6 +195,14 @@ function CreateTestFunction(template, object, keys) { ...@@ -190,6 +195,14 @@ function CreateTestFunction(template, object, keys) {
return () => func(object, keys); return () => func(object, keys);
} }
function CombineTestFunctions(tests) {
return () => {
for (var i = 0; i < tests.length; i++ ) {
tests[i]();
}
};
}
var TestFunctions = [ var TestFunctions = [
{ {
name: "in", name: "in",
...@@ -241,16 +254,18 @@ for (var test_function_desc of TestFunctions) { ...@@ -241,16 +254,18 @@ for (var test_function_desc of TestFunctions) {
for (var test_data of TestData) { for (var test_data of TestData) {
var name = suit_name + "--" + test_data.name; var name = suit_name + "--" + test_data.name;
var tests = [];
for (var object of test_data.objects) { for (var object of test_data.objects) {
var keys = test_function_desc.keys(object); var keys = test_function_desc.keys(object);
keys = MakeKeyQueries(keys, query_kind); keys = MakeKeyQueries(keys, query_kind);
var test_function = CreateTestFunction(test_function_desc.template, var test = CreateTestFunction(test_function_desc.template, object,
object, keys); keys);
tests.push(test);
var benchmark = new Benchmark(name, false, true, 400, test_function);
benchmarks.push(benchmark);
} }
var run_function = CombineTestFunctions(tests);
var benchmark = new Benchmark(name, false, false, 0, run_function);
benchmarks.push(benchmark);
} }
Benchmarks.push(new BenchmarkSuite(suit_name, [100], benchmarks)); Benchmarks.push(new BenchmarkSuite(suit_name, [100], benchmarks));
} }
......
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