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

[jstests] Change sorting benchmarks to run setup for each iteration

This CL changes all ArraySort benchmarks to execute the setup
function for each iteration (one run call), instead of only once for
all iterations.

Even though we now also measure the time needed to copy and prepare
the array, this is needed, otherwise we would mainly measure sorting
already sorted arrays.

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

Change-Id: I2e0e301b52b0288b8c825c3c8401c348c4a0dee7
Reviewed-on: https://chromium-review.googlesource.com/1105045Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Simon Zünd <szuend@google.com>
Cr-Commit-Position: refs/heads/master@{#53825}
parent 0db5e7b8
......@@ -74,11 +74,8 @@ function CreatePackedObjectArray() {
}
function CreateHoleySmiArray() {
array_to_sort = new Array(kArraySize);
for (let i = 0; i < kArraySize; ++i) {
array_to_sort[i] = template_array[i];
}
array_to_sort = Array.from(template_array);
delete array_to_sort[0];
AssertHoleySmiElements();
}
......@@ -126,3 +123,23 @@ function cmp_smaller(a, b) {
}
function cmp_greater(a, b) { return cmp_smaller(b, a); }
// The counter is used in some benchmarks to trigger actions during sorting.
// To keep benchmarks deterministic, the counter needs to be reset for each
// iteration.
let counter = 0;
// Sorting benchmarks need to execute setup and tearDown for each iteration.
// Otherwise the benchmarks would mainly measure sorting already sorted arrays
// which, depending on the strategy, is either the worst- or best case.
function createSortSuite(name, reference, run, setup, tearDown = () => {}) {
let run_fn = () => {
counter = 0;
setup();
run();
tearDown();
};
return createSuite(name, reference, run_fn);
}
......@@ -8,7 +8,6 @@ load('sort-base.js');
// after a set amount of comparisons. The transform function should cause the
// element kind of the array to change.
function CreateCompareFn(transformfn) {
let counter = 0;
return (a, b) => {
++counter;
if (counter == kArraySize/2) {
......@@ -23,22 +22,22 @@ let cmp_packed_smi_to_double = CreateCompareFn(() => array_to_sort.push(0.1));
let cmp_holey_smi_to_double = CreateCompareFn(() => array_to_sort.push(0.1));
let cmp_double_to_double = CreateCompareFn(() => array_to_sort.length *= 2);
createSuite(
createSortSuite(
'PackedSmiToPackedDouble', 1000, CreateSortFn([cmp_packed_smi_to_double]),
CreatePackedSmiArray, AssertPackedDoubleElements);
createSuite(
createSortSuite(
'HoleySmiToHoleyDouble', 1000, CreateSortFn([cmp_holey_smi_to_double]),
CreateHoleySmiArray, AssertHoleyDoubleElements);
createSuite(
createSortSuite(
'PackedDoubleToHoleyDouble', 1000, CreateSortFn([cmp_double_to_double]),
CreatePackedDoubleArray, AssertHoleyDoubleElements);
let cmp_packed_to_dict = CreateCompareFn(() => array_to_sort[%MaxSmi()] = 42);
let cmp_holey_to_dict = CreateCompareFn(() => array_to_sort[%MaxSmi()] = 42);
createSuite(
createSortSuite(
'PackedElementToDictionary', 1000, CreateSortFn([cmp_packed_to_dict]),
CreatePackedObjectArray, AssertDictionaryElements);
createSuite(
createSortSuite(
'HoleyElementToDictionary', 1000, CreateSortFn([cmp_holey_to_dict]),
CreateHoleyObjectArray, AssertDictionaryElements);
......@@ -9,12 +9,12 @@ load('sort-base.js');
// other sort benchmarks have monomorphic call sites.
let sortfn = CreateSortFn([cmp_smaller, cmp_greater]);
createSuite('PackedSmi', 1000, sortfn, CreatePackedSmiArray);
createSuite('PackedDouble', 1000, sortfn, CreatePackedDoubleArray);
createSuite('PackedElement', 1000, sortfn, CreatePackedObjectArray);
createSortSuite('PackedSmi', 1000, sortfn, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, sortfn, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, sortfn, CreatePackedObjectArray);
createSuite('HoleySmi', 1000, sortfn, CreateHoleySmiArray);
createSuite('HoleyDouble', 1000, sortfn, CreateHoleyDoubleArray);
createSuite('HoleyElement', 1000, sortfn, CreateHoleyObjectArray);
createSortSuite('HoleySmi', 1000, sortfn, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, sortfn, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, sortfn, CreateHoleyObjectArray);
createSuite('Dictionary', 1000, sortfn, CreateDictionaryArray);
createSortSuite('Dictionary', 1000, sortfn, CreateDictionaryArray);
......@@ -15,6 +15,6 @@ function SetupMegamorphic() {
Array.prototype.sort.call({});
}
createSuite('Base', 1000, Sort, SetupMegamorphic);
createSuite('MultipleCompareFns', 1000,
createSortSuite('Base', 1000, Sort, SetupMegamorphic);
createSortSuite('MultipleCompareFns', 1000,
CreateSortFn([cmp_smaller, cmp_greater]), SetupMegamorphic);
......@@ -85,14 +85,16 @@ let SetupUpUp = () => SetupPreSortedHalfs(Up, Up);
let SetupDownDown = () => SetupPreSortedHalfs(Down, Down);
let SetupDownUp = () => SetupPreSortedHalfs(Down, Up);
createSuite('Up', 1000, SortAsc, () => Up(array_to_sort, kLength), TearDown);
createSuite('Down', 1000, SortAsc, () => Down(array_to_sort, kLength), TearDown);
createSuite('Saw1000', 1000, SortAsc, SetupSaw1000, TearDown);
createSuite('Saw500', 1000, SortAsc, SetupSaw500, TearDown);
createSuite('Saw200', 1000, SortAsc, SetupSaw200, TearDown);
createSuite('Saw200Symmetric', 1000, SortAsc, SetupSaw200Sym, TearDown);
createSuite('Saw200Down', 1000, SortAsc, SetupSaw200Down, TearDown);
createSuite('UpDown', 1000, SortAsc, SetupUpDown, TearDown);
createSuite('UpUp', 1000, SortAsc, SetupUpUp, TearDown);
createSuite('DownDown', 1000, SortAsc, SetupDownDown, TearDown);
createSuite('DownUp', 1000, SortAsc, SetupDownUp, TearDown);
createSortSuite(
'Up', 1000, SortAsc, () => Up(array_to_sort, kLength), TearDown);
createSortSuite(
'Down', 1000, SortAsc, () => Down(array_to_sort, kLength), TearDown);
createSortSuite('Saw1000', 1000, SortAsc, SetupSaw1000, TearDown);
createSortSuite('Saw500', 1000, SortAsc, SetupSaw500, TearDown);
createSortSuite('Saw200', 1000, SortAsc, SetupSaw200, TearDown);
createSortSuite('Saw200Symmetric', 1000, SortAsc, SetupSaw200Sym, TearDown);
createSortSuite('Saw200Down', 1000, SortAsc, SetupSaw200Down, TearDown);
createSortSuite('UpDown', 1000, SortAsc, SetupUpDown, TearDown);
createSortSuite('UpUp', 1000, SortAsc, SetupUpUp, TearDown);
createSortSuite('DownDown', 1000, SortAsc, SetupDownDown, TearDown);
createSortSuite('DownUp', 1000, SortAsc, SetupDownUp, TearDown);
......@@ -4,12 +4,12 @@
load('sort-base.js');
createSuite('PackedSmi', 1000, Sort, CreatePackedSmiArray);
createSuite('PackedDouble', 1000, Sort, CreatePackedDoubleArray);
createSuite('PackedElement', 1000, Sort, CreatePackedObjectArray);
createSortSuite('PackedSmi', 1000, Sort, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, Sort, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, Sort, CreatePackedObjectArray);
createSuite('HoleySmi', 1000, Sort, CreateHoleySmiArray);
createSuite('HoleyDouble', 1000, Sort, CreateHoleyDoubleArray);
createSuite('HoleyElement', 1000, Sort, CreateHoleyObjectArray);
createSortSuite('HoleySmi', 1000, Sort, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, Sort, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, Sort, CreateHoleyObjectArray);
createSuite('Dictionary', 1000, Sort, CreateDictionaryArray);
createSortSuite('Dictionary', 1000, Sort, CreateDictionaryArray);
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