[js-perf-test] Add TypedArray#filter micro-benchmark

Bug: v8:8906
Change-Id: I61c04471530ecf8b97e1e6a0670f52f55232395e
Reviewed-on: https://chromium-review.googlesource.com/c/1497517
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60009}
This commit is contained in:
peterwmwong 2019-03-04 07:54:40 -06:00 committed by Commit Bot
parent d2a0df3fe1
commit f5ab50710d
2 changed files with 69 additions and 0 deletions

View File

@ -787,6 +787,20 @@
"resources": ["construct-all-typedarrays.js"],
"test_flags": ["construct-all-typedarrays"]
},
{
"name": "FilterNoSpecies",
"main": "run.js",
"resources": ["filter-nospecies.js"],
"test_flags": ["filter-nospecies"],
"results_regexp": "^TypedArrays\\-%s\\(Score\\): (.+)$",
"tests": [
{"name": "Uint8Array"},
{"name": "Uint16Array"},
{"name": "Uint32Array"},
{"name": "Float32Array"},
{"name": "Float64Array"}
]
},
{
"name": "JoinBigIntTypes",
"main": "run.js",

View File

@ -0,0 +1,55 @@
// Copyright 2019 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.
const SIZE = 1024;
let input;
let output;
function CreateSetup(TAConstructor) {
return () => {
// Create an Typed Array with a sequence of number 0 to SIZE.
const values = Array.from({ length: SIZE }).map((_, i) =>
TAConstructor === BigUint64Array ? BigInt(i) : i
);
input = new TAConstructor(values);
};
}
// Creates a run function that is unpolluted by IC feedback.
function CreateRun() {
// Filters out every other (odd indexed) elements.
return new Function(`
output = input.filter((el, i) => el < SIZE && (i % 2) === 0);
`);
}
function isOutputInvalid() {
if (output.length !== input.length / 2) return true;
// Verfies every other (odd indexed) element has been filtered out.
for (let i = 0; i < SIZE / 2; i++) {
if (output[i] !== input[i * 2]) return true;
}
}
function TearDown() {
if (isOutputInvalid()) throw new TypeError(`Unexpected result!\n${output}`);
input = void 0;
output = void 0;
}
createSuite(
'Uint8Array', 1000, CreateRun(), CreateSetup(Uint8Array), TearDown);
createSuite(
'Uint16Array', 1000, CreateRun(), CreateSetup(Uint16Array), TearDown);
createSuite(
'Uint32Array', 1000, CreateRun(), CreateSetup(Uint32Array), TearDown);
createSuite(
'Float32Array', 1000, CreateRun(), CreateSetup(Float32Array), TearDown);
createSuite(
'Float64Array', 1000, CreateRun(), CreateSetup(Float64Array), TearDown);
createSuite(
'BigUint64Array', 1000, CreateRun(), CreateSetup(BigUint64Array),
TearDown);