Commit 9018bb1a authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Add basic Array.p.sort benchmarks for the different element kinds.

The sort benchmarks are currently in their own directory, because we
might want to run them in isolation during the upcoming sort rework.

R=jgruber@chromium.org, petermarshall@chromium.org

Bug: v8:7382
Change-Id: Ic2e4e34d2838690529511d591099a66d0b908b0a
Reviewed-on: https://chromium-review.googlesource.com/1004997Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Simon Zünd <szuend@google.com>
Cr-Commit-Position: refs/heads/master@{#52537}
parent e5a687be
// 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');
load('sort.js')
function benchy(name, test, testSetup) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test, testSetup)
]);
}
function PrintResult(name, result) {
print(name + '-ArraySort(Score): ' + result);
}
function PrintStep(name) {}
function PrintError(name, error) {
PrintResult(name, error);
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });
// 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 size = 10;
let template_array = [];
for (let i = 0; i < size; ++i) {
template_array[i] = Math.floor(Math.random() * size);
}
let packed_smi_array = Array.from(template_array);
let packed_double_array = Array.from(template_array, (x,_) => x + 0.1);
let packed_object_array = Array.from(template_array, (x,_) => `value ${x}`);
let holey_smi_array = new Array(size);
let holey_double_array = new Array(size);
let holey_object_array = new Array(size);
for (let i = 0; i < size; i += 5) {
const x = Math.floor(Math.random() * size);
holey_smi_array[i] = x;
holey_double_array[i] = x + 0.1;
holey_object_array[i] = `value ${x}`;
}
let dictionary_array = Array.from(template_array);
dictionary_array[%MaxSmi()] = 42;
function assert(condition, message) {
if (!condition) {
throw Error(message);
}
}
assert(%HasFastPackedElements(packed_smi_array) &&
%HasSmiElements(packed_smi_array),
"Element kind is not PACKED_SMI_ELEMENTS");
assert(%HasFastPackedElements(packed_double_array) &&
%HasDoubleElements(packed_double_array),
"Element kind is not PACKED_DOUBLE_ELEMENTS");
assert(%HasFastPackedElements(packed_object_array) &&
%HasObjectElements(packed_object_array),
"Element kind is not PACKED_ELEMENTS");
assert(%HasHoleyElements(holey_smi_array) &&
%HasSmiElements(holey_smi_array),
"Element kind is not HOLEY_SMI_ELEMENTS");
assert(%HasHoleyElements(holey_double_array) &&
%HasDoubleElements(holey_double_array),
"Element kind is not HOLEY_DOUBLE_ELEMENTS");
assert(%HasHoleyElements(holey_object_array) &&
%HasObjectElements(holey_object_array),
"Element kind is not HOLEY_ELEMENTS");
assert(%HasDictionaryElements(dictionary_array),
"Element kind is not DICTIONARY_ELEMENTS");
function PackedSmiSort() {
packed_smi_array.sort();
}
function PackedDoubleSort() {
packed_double_array.sort();
}
function PackedElementSort() {
packed_object_array.sort();
}
function HoleySmiSort() {
holey_smi_array.sort();
}
function HoleyDoubleSort() {
holey_double_array.sort();
}
function HoleyElementSort() {
holey_object_array.sort();
}
function DictionarySort() {
dictionary_array.sort();
}
benchy('PackedSmi', PackedSmiSort);
benchy('PackedDouble', PackedDoubleSort);
benchy('PackedElement', PackedElementSort);
benchy('HoleySmi', HoleySmiSort);
benchy('HoleyDouble', HoleyDoubleSort);
benchy('HoleyElement', HoleyElementSort);
benchy('Dictionary', DictionarySort);
})();
......@@ -626,6 +626,25 @@
{"name": "MixedFrom"}
]
},
{
"name": "ArraySort",
"path": ["ArraySort"],
"main": "run.js",
"resources": ["sort.js"],
"flags": [
"--allow-natives-syntax"
],
"results_regexp": "^%s\\-ArraySort\\(Score\\): (.+)$",
"tests": [
{"name": "PackedSmi"},
{"name": "PackedDouble"},
{"name": "PackedElement"},
{"name": "HoleySmi"},
{"name": "HoleyDouble"},
{"name": "HoleyElement"},
{"name": "Dictionary"}
]
},
{
"name": "ForLoops",
"path": ["ForLoops"],
......
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