Commit f8f74270 authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

[js-perf-test] Add TypedArray#join micro-benchmarks

This patch adds micro-benchmarks for TypedArray#join with and without a separator.
The benchmark can be used to measure any TypedArray#join optimizations we implement in the future.

Test:

  tools/run_perf.py --binary-override-path=out/x64.release/d8 \
    --filter JSTests/TypedArrays/Join \
    test/js-perf-test/JSTests.json

Bug: v8:7624
Change-Id: I526af50da0eff400d21b807ba30a9de2c3d87476
Reviewed-on: https://chromium-review.googlesource.com/c/1369333Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarSergiy Belozorov <sergiyb@chromium.org>
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Cr-Commit-Position: refs/heads/master@{#58163}
parent e5fcd33b
......@@ -744,6 +744,42 @@
"resources": ["construct-all-typedarrays.js"],
"test_flags": ["construct-all-typedarrays"]
},
{
"name": "JoinBigIntTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-bigint.js"],
"test_flags": ["join-bigint"]
},
{
"name": "JoinFloatTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-float.js"],
"test_flags": ["join-float"]
},
{
"name": "JoinIntTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-int.js"],
"test_flags": ["join-int"]
},
{
"name": "JoinWithSeparatorBigIntTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-sep-bigint.js"],
"test_flags": ["join-sep-bigint"]
},
{
"name": "JoinWithSeparatorFloatTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-sep-float.js"],
"test_flags": ["join-sep-float"]
},
{
"name": "JoinWithSeparatorIntTypes",
"main": "run.js",
"resources": ["base.js", "join.js", "join-sep-int.js"],
"test_flags": ["join-sep-int"]
},
{
"name": "SetFromArrayLike",
"main": "run.js",
......@@ -771,37 +807,37 @@
{
"name": "SortIntTypes",
"main": "run.js",
"resources": ["sort.js", "sort-int.js"],
"resources": ["base.js", "sort.js", "sort-int.js"],
"test_flags": ["sort-int"]
},
{
"name": "SortBigIntTypes",
"main": "run.js",
"resources": ["sort.js", "sort-bigint.js"],
"resources": ["base.js", "sort.js", "sort-bigint.js"],
"test_flags": ["sort-bigint"]
},
{
"name": "SortFloatTypes",
"main": "run.js",
"resources": ["sort.js", "sort-float.js"],
"resources": ["base.js", "sort.js", "sort-float.js"],
"test_flags": ["sort-float"]
},
{
"name": "SortCustomCompareFnIntTypes",
"main": "run.js",
"resources": ["sort.js", "sort-cmpfn-int.js"],
"resources": ["base.js", "sort.js", "sort-cmpfn-int.js"],
"test_flags": ["sort-cmpfn-int"]
},
{
"name": "SortCustomCompareFnBigIntTypes",
"main": "run.js",
"resources": ["sort.js", "sort-cmpfn-bigint.js"],
"resources": ["base.js", "sort.js", "sort-cmpfn-bigint.js"],
"test_flags": ["sort-cmpfn-bigint"]
},
{
"name": "SortCustomCompareFnFloatTypes",
"main": "run.js",
"resources": ["sort.js", "sort-cmpfn-float.js"],
"resources": ["base.js", "sort.js", "sort-cmpfn-float.js"],
"test_flags": ["sort-cmpfn-float"]
},
{
......
// Copyright 2018 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 typedArrayIntConstructors = [
{name: "Uint8", ctor: Uint8Array},
{name: "Int8", ctor: Int8Array},
{name: "Uint16", ctor: Uint16Array},
{name: "Int16", ctor: Int16Array},
{name: "Uint32", ctor: Uint32Array},
{name: "Int32", ctor: Int32Array},
{name: "Uint8Clamped", ctor: Uint8ClampedArray},
];
const typedArrayFloatConstructors = [
{name: "Float32", ctor: Float32Array},
{name: "Float64", ctor: Float64Array},
];
// "ref" builds might not yet have BigInt support, so the benchmark fails
// gracefully during setup (the constructor will be undefined), instead of
// a hard fail when this file is loaded.
const typedArrayBigIntConstructors = [
{name: "BigUint64", ctor: this["BigUint64Array"]},
{name: "BigInt64", ctor: this["BigInt64Array"]}
];
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinBigIntTypes', [100],
CreateBenchmarks(typedArrayBigIntConstructors, false));
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinFloatTypes', [100],
CreateBenchmarks(typedArrayFloatConstructors, false));
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinIntTypes', [100],
CreateBenchmarks(typedArrayIntConstructors, false));
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinWithSeparatorBigIntTypes', [100],
CreateBenchmarks(typedArrayBigIntConstructors, true));
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinWithSeparatorFloatTypes', [100],
CreateBenchmarks(typedArrayFloatConstructors, true));
// Copyright 2018 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.
load('join.js');
new BenchmarkSuite('JoinWithSeparatorIntTypes', [100],
CreateBenchmarks(typedArrayIntConstructors, true));
// Copyright 2018 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.
load('base.js');
function CreateBenchmarks(constructors, withSep) {
return constructors.map(({ ctor, name }) =>
new Benchmark(`Join${name}`, false, false, 0, CreateJoinFn(withSep),
CreateSetupFn(ctor), TearDown)
);
}
const kInitialArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let result;
let arrayToJoin = [];
function CreateSetupFn(constructor) {
return () => {
if (constructor == BigUint64Array || constructor == BigInt64Array) {
arrayToJoin = constructor.from(kInitialArray, x => BigInt(Math.floor(x)));
} else {
arrayToJoin = new constructor(kInitialArray);
}
}
}
function CreateJoinFn(withSep) {
if (withSep) {
return () => result = arrayToJoin.join(',');
} else {
return () => result = arrayToJoin.join('');
}
}
function TearDown() {
arrayToJoin = void 0;
}
......@@ -2,28 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let typedArrayIntConstructors = [
{name: "Uint8", ctor: Uint8Array},
{name: "Int8", ctor: Int8Array},
{name: "Uint16", ctor: Uint16Array},
{name: "Int16", ctor: Int16Array},
{name: "Uint32", ctor: Uint32Array},
{name: "Int32", ctor: Int32Array},
{name: "Uint8Clamped", ctor: Uint8ClampedArray},
];
let typedArrayFloatConstructors = [
{name: "Float32", ctor: Float32Array},
{name: "Float64", ctor: Float64Array},
];
// "ref" builds might not yet have BigInt support, so the benchmark fails
// gracefully during setup (the constructor will be undefined), instead of
// a hard fail when this file is loaded.
let typedArrayBigIntConstructors = [
{name: "BigUint64", ctor: this["BigUint64Array"]},
{name: "BigInt64", ctor: this["BigInt64Array"]}
];
load('base.js');
function CreateBenchmarks(constructors, comparefns = []) {
var 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