Commit 94f0abf9 authored by cbruni's avatar cbruni Committed by Commit bot

reland [js-perf-test] Adding micro benchmarks for for-in and keys patterns.

In order to track certain critical code-patters we will start adding
micro-benchmarks that reflect common requests on http://jsperf.com.
In this first CL a number of property enumeration methods are added,
in the hope to get a clearer picture on future regressions.

BUG=

Review URL: https://codereview.chromium.org/1702613002

Cr-Commit-Position: refs/heads/master@{#34425}
parent 820e27f9
...@@ -142,11 +142,14 @@ ...@@ -142,11 +142,14 @@
"main": "run.js", "main": "run.js",
"resources": ["keys.js"], "resources": ["keys.js"],
"results_regexp": "^%s\\-Keys\\(Score\\): (.+)$", "results_regexp": "^%s\\-Keys\\(Score\\): (.+)$",
"run_count": 3,
"run_count_android_arm": 2,
"run_count_android_arm64": 2,
"tests": [ "tests": [
{"name": "Object.keys()"}, {"name": "Object.keys()"},
{"name": "for (in)"}, {"name": "for-in"},
{"name": "for (in) hasOwnProperty()"}, {"name": "for-in hasOwnProperty()"},
{"name": "for Object.keys()"}, {"name": "for (i < Object.keys().length)"},
{"name": "Object.keys().forEach()"}, {"name": "Object.keys().forEach()"},
{"name": "for (i < array.length)"}, {"name": "for (i < array.length)"},
{"name": "for (i < length)"} {"name": "for (i < length)"}
......
// Copyright 2015 the V8 project authors. All rights reserved. // Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -58,10 +58,10 @@ function IntArray(size) { ...@@ -58,10 +58,10 @@ function IntArray(size) {
var object_empty = {}; var object_empty = {};
var array_empty = []; var array_empty = [];
var array_int_100 = IntArray(100); var array_int_50 = IntArray(50);
var array_int_100_proto_elements = IntArray(100); var array_int_50_proto_elements = IntArray(50);
array_int_100_proto_elements.__proto__ = [101, 102, 103, 104]; array_int_50_proto_elements.__proto__ = [51, 52, 53, 54];
var array_int_holey_100 = HoleyIntArray(100); var array_int_holey_50 = HoleyIntArray(50);
var empty_proto_5_10 = ObjectWithKeys(5); var empty_proto_5_10 = ObjectWithKeys(5);
empty_proto_5_10.__proto__ = ObjectWithProtoKeys(10, 0); empty_proto_5_10.__proto__ = ObjectWithProtoKeys(10, 0);
...@@ -80,21 +80,20 @@ for (var i = 0; i < 5; i++) { ...@@ -80,21 +80,20 @@ for (var i = 0; i < 5; i++) {
var TestObjects = { var TestObjects = {
object_empty: object_empty, object_empty: object_empty,
array_empty: array_empty, array_empty: array_empty,
array_int_100: array_int_100, array_int_50: array_int_50,
array_int_holey_100: array_int_holey_100, array_int_holey_50: array_int_holey_50,
array_int_100_proto_elements: array_int_100_proto_elements, array_int_50_proto_elements: array_int_50_proto_elements,
empty_proto_5_10: empty_proto_5_10, empty_proto_5_10: empty_proto_5_10,
empty_proto_5_5_slow: empty_proto_5_5_slow, empty_proto_5_5_slow: empty_proto_5_5_slow,
object_elements_proto_5_10: object_elements_proto_5_10 object_elements_proto_5_10: object_elements_proto_5_10
} }
var TestArrays = var TestArrays = {
{ array_empty: array_empty,
array_empty: array_empty, array_int_50: array_int_50,
array_int_100: array_int_100, array_int_holey_50: array_int_holey_50,
array_int_holey_100: array_int_holey_100, array_int_50_proto_elements: array_int_50_proto_elements,
array_int_100_proto_elements: array_int_100_proto_elements }
}
// ============================================================================ // ============================================================================
...@@ -108,7 +107,7 @@ function CreateTestFunctionGen(fn) { ...@@ -108,7 +107,7 @@ function CreateTestFunctionGen(fn) {
var TestFunctions = { var TestFunctions = {
"Object.keys()": CreateTestFunctionGen(() => {return Object.keys(object)}), "Object.keys()": CreateTestFunctionGen(() => {return Object.keys(object)}),
"for (in)": CreateTestFunctionGen(() => { "for-in": CreateTestFunctionGen(() => {
var count = 0; var count = 0;
var result; var result;
for (var key in object) { for (var key in object) {
...@@ -117,7 +116,7 @@ var TestFunctions = { ...@@ -117,7 +116,7 @@ var TestFunctions = {
}; };
return [result, count]; return [result, count];
}), }),
"for (in) hasOwnProperty()": CreateTestFunctionGen(() => { "for-in hasOwnProperty()": CreateTestFunctionGen(() => {
var count = 0; var count = 0;
var result; var result;
for (var key in object) { for (var key in object) {
...@@ -130,7 +129,8 @@ var TestFunctions = { ...@@ -130,7 +129,8 @@ var TestFunctions = {
"for (i < Object.keys().length)": CreateTestFunctionGen(() => { "for (i < Object.keys().length)": CreateTestFunctionGen(() => {
var count = 0; var count = 0;
var result; var result;
var keys = Object.keys(object) for (var i = 0; i < keys.length; i++) { var keys = Object.keys(object);
for (var i = 0; i < keys.length; i++) {
count++; count++;
result = object[keys[i]]; result = object[keys[i]];
}; };
...@@ -170,7 +170,8 @@ var TestFunctionsArrays = { ...@@ -170,7 +170,8 @@ var TestFunctionsArrays = {
} }
// ============================================================================ // ============================================================================
// Create the benchmark suites. We create a suite for each of the test
// functions above and each suite contains benchmarks for each object type.
var Benchmarks = []; var Benchmarks = [];
function NewBenchmark( function NewBenchmark(
...@@ -190,7 +191,7 @@ for (var test_function_name in TestFunctions) { ...@@ -190,7 +191,7 @@ for (var test_function_name in TestFunctions) {
test_function_gen, test_function_name, test_object, test_object_name); test_function_gen, test_function_name, test_object, test_object_name);
benchmarks.push(benchmark); benchmarks.push(benchmark);
} }
Benchmarks.push(new BenchmarkSuite(test_function_name, [1000], benchmarks)); Benchmarks.push(new BenchmarkSuite(test_function_name, [100], benchmarks));
} }
for (var test_function_name in TestFunctionsArrays) { for (var test_function_name in TestFunctionsArrays) {
...@@ -202,7 +203,7 @@ for (var test_function_name in TestFunctionsArrays) { ...@@ -202,7 +203,7 @@ for (var test_function_name in TestFunctionsArrays) {
test_function_gen, test_function_name, test_array, test_array_name); test_function_gen, test_function_name, test_array, test_array_name);
benchmarks.push(benchmark); benchmarks.push(benchmark);
} }
Benchmarks.push(new BenchmarkSuite(test_function_name, [1000], benchmarks)); Benchmarks.push(new BenchmarkSuite(test_function_name, [100], benchmarks));
} }
// ============================================================================ // ============================================================================
// Copyright 2014 the V8 project authors. All rights reserved. // Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
......
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