Commit 3953955a authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Extend the existing TypedArray.sort benchmark.

Benchmark now sorts every element type of TypedArray and groups the
benchmarks by integer and floating point types. Also adding a sort
benchmark that uses multiple custom compare functions.

R=petermarshall@chromium.org

Bug: v8:7624
Change-Id: Id0f44adf78398c99a17fe3edb6ee5d7fccc4d99b
Reviewed-on: https://chromium-review.googlesource.com/1000774
Commit-Queue: Simon Zünd <szuend@google.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52541}
parent f23e6e88
...@@ -518,10 +518,28 @@ ...@@ -518,10 +518,28 @@
"test_flags": ["slice-nospecies"] "test_flags": ["slice-nospecies"]
}, },
{ {
"name": "Sort", "name": "SortIntTypes",
"main": "run.js", "main": "run.js",
"resources": ["sort.js"], "resources": ["sort-int.js"],
"test_flags": ["sort"] "test_flags": ["sort-int"]
},
{
"name": "SortFloatTypes",
"main": "run.js",
"resources": ["sort-float.js"],
"test_flags": ["sort-float"]
},
{
"name": "SortCustomCompareFnIntTypes",
"main": "run.js",
"resources": ["sort-cmpfn-int.js"],
"test_flags": ["sort-cmpfn-int"]
},
{
"name": "SortCustomCompareFnFloatTypes",
"main": "run.js",
"resources": ["sort-cmpfn-float.js"],
"test_flags": ["sort-cmpfn-float"]
}, },
{ {
"name": "SubarrayNoSpecies", "name": "SubarrayNoSpecies",
......
// 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('sort.js');
new BenchmarkSuite('SortCustomCompareFnFloatTypes', [1000],
CreateBenchmarks(typedArrayFloatConstructors,
[cmp_smaller, cmp_greater]));
// 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('sort.js');
new BenchmarkSuite('SortCustomCompareFnIntTypes', [1000],
CreateBenchmarks(typedArrayIntConstructors,
[cmp_smaller, cmp_greater]));
// 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('sort.js');
new BenchmarkSuite('SortFloatTypes', [1000],
CreateBenchmarks(typedArrayFloatConstructors));
// 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('sort.js');
new BenchmarkSuite('SortIntTypes', [1000],
CreateBenchmarks(typedArrayIntConstructors));
// Copyright 2017 the V8 project authors. All rights reserved. // Copyright 2018 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.
new BenchmarkSuite('Sort', [1000], [ let typedArrayIntConstructors = [
new Benchmark('Sort', false, false, 0, {name: "Uint8", ctor: Uint8Array},
sortLarge, sortLargeSetup, sortLargeTearDown), {name: "Int8", ctor: Int8Array},
]); {name: "Uint16", ctor: Uint16Array},
{name: "Int16", ctor: Int16Array},
{name: "Uint32", ctor: Uint32Array},
{name: "Int32", ctor: Int32Array},
{name: "Uint8Clamped", ctor: Uint8ClampedArray},
];
var size = 3000; let typedArrayFloatConstructors = [
var initialLargeFloat64Array = new Array(size); {name: "Float32", ctor: Float32Array},
for (var i = 0; i < size; ++i) { {name: "Float64", ctor: Float64Array},
initialLargeFloat64Array[i] = Math.random(); ];
function CreateBenchmarks(constructors, comparefns = []) {
var benchmarks = [];
for (let constructor of constructors) {
benchmarks.push(new Benchmark('Sort' + constructor.name, false, false, 0,
CreateSortFn(comparefns),
CreateSetupFn(constructor.ctor), TearDown));
}
return benchmarks;
} }
initialLargeFloat64Array = new Float64Array(initialLargeFloat64Array);
var largeFloat64Array;
function sortLarge() { const size = 3000;
largeFloat64Array.sort(); const initialLargeArray = new Array(size);
for (let i = 0; i < size; ++i) {
initialLargeArray[i] = Math.random() * 3000;
} }
function sortLargeSetup() { let array_to_sort = [];
largeFloat64Array = new Float64Array(initialLargeFloat64Array);
function CreateSetupFn(constructor) {
return () => {
array_to_sort = new constructor(initialLargeArray);
}
} }
function sortLargeTearDown() { function CreateSortFn(comparefns) {
for (var i = 0; i < size - 1; ++i) { if (comparefns.length == 0) {
if (largeFloat64Array[i] > largeFloat64Array[i+1]) { return () => array_to_sort.sort();
throw new TypeError("Unexpected result!\n" + largeFloat64Array); }
return () => {
for (let cmpfn of comparefns) {
array_to_sort.sort(cmpfn);
} }
} }
largeFloat64Array = void 0;
} }
function TearDown() {
array_to_sort = void 0;
}
function cmp_smaller(a, b) {
if (a < b) return -1;
if (b < a) return 1;
return 0;
}
function cmp_greater(a, b) { cmp_smaller(b, a); }
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