Commit 1d174389 authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

[js-perf-test] Add Array.p.findIndex microbenchmarks

Bug: chromium:791045, v8:1956, v8:7165
Change-Id: I03f26bbbe65217cedf663af59ef5eb63a5dcf039
Reviewed-on: https://chromium-review.googlesource.com/810039
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49899}
parent 8d2657ba
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(() => {
function benchy(name, test, testSetup) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test, testSetup, ()=>{})
]);
}
benchy('NaiveFindIndexReplacement', Naive, NaiveSetup);
benchy('DoubleFindIndex', Double, DoubleSetup);
benchy('SmiFindIndex', Smi, SmiSetup);
benchy('FastFindIndex', Fast, FastSetup);
benchy('GenericFindIndex', Generic, ObjectSetup);
benchy('OptFastFindIndex', OptFast, FastSetup);
let array;
// Initialize func variable to ensure the first test doesn't benefit from
// global object property tracking.
let func = 0;
let result;
const array_size = 100;
const max_index = array_size - 1;
// Although these functions have the same code, they are separated for
// clean IC feedback.
function Double() {
result = array.findIndex(func);
}
function Smi() {
result = array.findIndex(func);
}
function Fast() {
result = array.findIndex(func);
}
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFast(multiple) {
// Use of variable multiple in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.findIndex((v, i, a) => v === `value ${multiple}`);
}
// Don't optimize because I want to optimize RunOptFast with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFast);
function OptFast() { RunOptFast(max_index); }
function Naive() {
let index = -1;
const length = array == null ? 0 : array.length;
for (let index = 0; index < length; index++) {
const value = array[index];
if (func(value, index, array)) {
result = value;
break;
}
}
}
function Generic() {
result = Array.prototype.findIndex.call(array, func);
}
function NaiveSetup() {
// Prime Naive with polymorphic cases.
array = [1, 2, 3];
func = (v, i, a) => v === max_index;
Naive();
Naive();
array = [3.4]; Naive();
array = new Array(10); array[0] = 'hello'; Naive();
SmiSetup();
delete array[1];
}
function SmiSetup() {
array = Array.from({ length: array_size }, (_, i) => i);
func = (value, index, object) => value === max_index;
}
function DoubleSetup() {
array = Array.from({ length: array_size }, (_, i) => i + 0.5);
func = (value, index, object) => value === max_index + 0.5;
}
function FastSetup() {
array = Array.from({ length: array_size }, (_, i) => `value ${i}`);
func = (value, index, object) => value === `value ${max_index}`;
}
function ObjectSetup() {
array = { length: array_size };
for (let i = 0; i < array_size; i++) {
array[i] = i;
}
func = (value, index, object) => value === max_index;
}
})();
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(() => {
function benchy(name, test, testSetup) {
new BenchmarkSuite(name, [1000],
......@@ -9,97 +10,99 @@ function benchy(name, test, testSetup) {
]);
}
benchy('NaiveFindReplacement', NaiveFind, NaiveFindSetup);
benchy('DoubleFind', DoubleFind, DoubleFindSetup);
benchy('SmiFind', SmiFind, SmiFindSetup);
benchy('FastFind', FastFind, FastFindSetup);
benchy('GenericFind', GenericFind, ObjectFindSetup);
benchy('OptFastFind', OptFastFind, FastFindSetup);
benchy('NaiveFindReplacement', Naive, NaiveSetup);
benchy('DoubleFind', Double, DoubleSetup);
benchy('SmiFind', Smi, SmiSetup);
benchy('FastFind', Fast, FastSetup);
benchy('GenericFind', Generic, ObjectSetup);
benchy('OptFastFind', OptFast, FastSetup);
let find_array;
let array;
// Initialize func variable to ensure the first test doesn't benefit from
// global object property tracking.
let find_func = 0;
let find_result;
const find_array_size = 100;
const find_max_index = find_array_size - 1;
let func = 0;
let result;
const array_size = 100;
const max_index = array_size - 1;
// Although these functions have the same code, they are separated for
// clean IC feedback.
function DoubleFind() {
find_result = find_array.find(find_func);
function Double() {
result = array.find(func);
}
function SmiFind() {
find_result = find_array.find(find_func);
function Smi() {
result = array.find(func);
}
function FastFind() {
find_result = find_array.find(find_func);
function Fast() {
result = array.find(func);
}
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastFind(multiple) {
function RunOptFast(multiple) {
// Use of variable multiple in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
find_result = find_array.find((v, i, a) => v === `value ${multiple}`);
result = array.find((v, i, a) => v === `value ${multiple}`);
}
// Don't optimize because I want to optimize RunOptFastFind with a parameter
// Don't optimize because I want to optimize RunOptFast with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastFind);
function OptFastFind() { RunOptFastFind(find_max_index); }
%NeverOptimizeFunction(OptFast);
function OptFast() { RunOptFast(max_index); }
function NaiveFind() {
function Naive() {
let index = -1;
const length = find_array == null ? 0 : find_array.length;
const length = array == null ? 0 : array.length;
for (let index = 0; index < length; index++) {
const value = find_array[index];
if (find_func(value, index, find_array)) {
find_result = value;
const value = array[index];
if (func(value, index, array)) {
result = value;
break;
}
}
}
function GenericFind() {
find_result = Array.prototype.find.call(find_array, find_func);
function Generic() {
result = Array.prototype.find.call(array, func);
}
function NaiveFindSetup() {
// Prime NaiveFind with polymorphic cases.
find_array = [1, 2, 3];
find_func = (v, i, a) => v === find_max_index;
NaiveFind();
NaiveFind();
find_array = [3.4]; NaiveFind();
find_array = new Array(10); find_array[0] = 'hello'; NaiveFind();
SmiFindSetup();
delete find_array[1];
function NaiveSetup() {
// Prime Naive with polymorphic cases.
array = [1, 2, 3];
func = (v, i, a) => v === max_index;
Naive();
Naive();
array = [3.4]; Naive();
array = new Array(10); array[0] = 'hello'; Naive();
SmiSetup();
delete array[1];
}
function SmiFindSetup() {
find_array = Array.from({ length: find_array_size }, (_, i) => i);
find_func = (value, index, object) => value === find_max_index;
function SmiSetup() {
array = Array.from({ length: array_size }, (_, i) => i);
func = (value, index, object) => value === max_index;
}
function DoubleFindSetup() {
find_array = Array.from({ length: find_array_size }, (_, i) => i + 0.5);
find_func = (value, index, object) => value === find_max_index + 0.5;
function DoubleSetup() {
array = Array.from({ length: array_size }, (_, i) => i + 0.5);
func = (value, index, object) => value === max_index + 0.5;
}
function FastFindSetup() {
find_array = Array.from({ length: find_array_size }, (_, i) => `value ${i}`);
find_func = (value, index, object) => value === `value ${find_max_index}`;
function FastSetup() {
array = Array.from({ length: array_size }, (_, i) => `value ${i}`);
func = (value, index, object) => value === `value ${max_index}`;
}
function ObjectFindSetup() {
find_array = { length: find_array_size };
for (let i = 0; i < find_array_size; i++) {
find_array[i] = i;
function ObjectSetup() {
array = { length: array_size };
for (let i = 0; i < array_size; i++) {
array[i] = i;
}
find_func = (value, index, object) => value === find_max_index;
func = (value, index, object) => value === max_index;
}
})();
......@@ -14,6 +14,7 @@ load('reduce.js');
load('reduce-right.js');
load('to-string.js');
load('find.js');
load('find-index.js');
var success = true;
......
......@@ -428,7 +428,13 @@
{"name": "SmiFind"},
{"name": "FastFind"},
{"name": "GenericFind"},
{"name": "OptFastFind"}
{"name": "OptFastFind"},
{"name": "NaiveFindIndexReplacement"},
{"name": "DoubleFindIndex"},
{"name": "SmiFindIndex"},
{"name": "FastFindIndex"},
{"name": "GenericFindIndex"},
{"name": "OptFastFindIndex"}
]
},
{
......
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