From c6d5179bad879decf4f74e403004ca008f529b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Thu, 21 Jun 2018 12:49:16 +0200 Subject: [PATCH] [jstest] Add benchmarks that sort arrays of different lengths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All other sorting benchmarks use arrays of roughly the same length. This CL adds a set of benchmarks that sort arrays of various lengths. Two data configurations are used for each length: Completely random and already sorted. R=jgruber@chromium.org Bug: v8:7382 Change-Id: Ib80a3421a68029c8e4f823605bab7b2d7fe1ae34 Reviewed-on: https://chromium-review.googlesource.com/1109509 Commit-Queue: Simon Zünd Reviewed-by: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#53917} --- test/js-perf-test/ArraySort/sort-lengths.js | 40 +++++++++++++++++++++ test/js-perf-test/JSTests.json | 23 ++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/js-perf-test/ArraySort/sort-lengths.js diff --git a/test/js-perf-test/ArraySort/sort-lengths.js b/test/js-perf-test/ArraySort/sort-lengths.js new file mode 100644 index 0000000000..aa681295c1 --- /dev/null +++ b/test/js-perf-test/ArraySort/sort-lengths.js @@ -0,0 +1,40 @@ +// 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-base.js'); + +function SortAsc() { + array_to_sort.sort(cmp_smaller); +} + +function Random(length) { + for (let i = 0; i < length; ++i) { + array_to_sort.push(Math.floor(Math.random()) * length); + } + AssertPackedSmiElements(); +} + +function Sorted(length) { + for (let i = 0; i < length; ++i) { + array_to_sort.push(i); + } + AssertPackedSmiElements(); +} + +function TearDown() { + array_to_sort = []; +} + +function CreateSortSuitesForLength(length) { + createSortSuite( + 'Random' + length, 1000, SortAsc, () => Random(length), TearDown); + createSortSuite( + 'Sorted' + length, 1000, SortAsc, () => Sorted(length), TearDown); +} + +CreateSortSuitesForLength(10); +CreateSortSuitesForLength(100); +CreateSortSuitesForLength(1000); +CreateSortSuitesForLength(10000); +CreateSortSuitesForLength(100000); diff --git a/test/js-perf-test/JSTests.json b/test/js-perf-test/JSTests.json index d434a503db..5719f86f6d 100644 --- a/test/js-perf-test/JSTests.json +++ b/test/js-perf-test/JSTests.json @@ -810,6 +810,29 @@ {"name": "MultipleCompareFns"} ] }, + { + "name": "ArraySortDifferentLengths", + "path": ["ArraySort"], + "main": "run.js", + "resources": ["sort-base.js", "sort-lengths.js"], + "test_flags": ["sort-lengths"], + "results_regexp": "^%s\\-ArraySort\\(Score\\): (.+)$", + "flags": [ + "--allow-natives-syntax" + ], + "tests": [ + {"name": "Random10"}, + {"name": "Sorted10"}, + {"name": "Random100"}, + {"name": "Sorted100"}, + {"name": "Random1000"}, + {"name": "Sorted1000"}, + {"name": "Random10000"}, + {"name": "Sorted10000"}, + {"name": "Random100000"}, + {"name": "Sorted100000"} + ] + }, { "name": "ForLoops", "path": ["ForLoops"],