From 05b7308aec8593063573a048d9669c2ac259b7c9 Mon Sep 17 00:00:00 2001 From: Hai Dang Date: Mon, 15 Oct 2018 16:16:05 +0200 Subject: [PATCH] [js-perf-tests] Add micro-benchmarks for copying double arrays. Bug: v8:7980 Change-Id: I6e7f1c064830c0055f8708472b62221ab5ca3288 Reviewed-on: https://chromium-review.googlesource.com/c/1280325 Reviewed-by: Georg Neis Commit-Queue: Hai Dang Cr-Commit-Position: refs/heads/master@{#56647} --- .../run.js | 158 +++++++++++++++++ .../run.js | 151 +++++++++++++++++ .../run.js | 159 ++++++++++++++++++ .../run.js | 154 +++++++++++++++++ test/js-perf-test/JSTests.json | 68 ++++++++ 5 files changed, 690 insertions(+) create mode 100644 test/js-perf-test/ArrayLiteralInitialSpreadLargeDoubleHoley/run.js create mode 100644 test/js-perf-test/ArrayLiteralInitialSpreadLargeDoublePacked/run.js create mode 100644 test/js-perf-test/ArrayLiteralInitialSpreadSmallDoubleHoley/run.js create mode 100644 test/js-perf-test/ArrayLiteralInitialSpreadSmallDoublePacked/run.js diff --git a/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoubleHoley/run.js b/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoubleHoley/run.js new file mode 100644 index 0000000000..72b83a3ada --- /dev/null +++ b/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoubleHoley/run.js @@ -0,0 +1,158 @@ +// 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. + +// Comparing different copy schemes against spread initial literals. +// Benchmarks for large holey double arrays. + +const largeHoleyArray = new Array(1e5); + +for (var i = 0; i < 100; i++) { + largeHoleyArray[i] = i + 6.66; +} + +for (var i = 5000; i < 5500; i++) { + largeHoleyArray[i] = i + 6.66; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Spread +// ---------------------------------------------------------------------------- + +function SpreadLargeHoley() { + var newArr = [...largeHoleyArray]; + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLength +// ---------------------------------------------------------------------------- + +function ForLengthLargeHoley() { + var newArr = new Array(largeHoleyArray.length); + for (let i = 0; i < largeHoleyArray.length; i++) { + newArr[i] = largeHoleyArray[i]; + } + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLengthEmpty +// ---------------------------------------------------------------------------- + +function ForLengthEmptyLargeHoley() { + var newArr = []; + for (let i = 0; i < largeHoleyArray.length; i++) { + newArr[i] = largeHoleyArray[i]; + } + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice +// ---------------------------------------------------------------------------- + +function SliceLargeHoley() { + var newArr = largeHoleyArray.slice(); + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice0 +// ---------------------------------------------------------------------------- + +function Slice0LargeHoley() { + var newArr = largeHoleyArray.slice(0); + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatReceive +// ---------------------------------------------------------------------------- + +function ConcatReceiveLargeHoley() { + var newArr = largeHoleyArray.concat(); + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatArg +// ---------------------------------------------------------------------------- + +function ConcatArgLargeHoley() { + var newArr = [].concat(largeHoleyArray); + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForOfPush +// ---------------------------------------------------------------------------- + +function ForOfPushLargeHoley() { + var newArr = []; + for (let x of largeHoleyArray) { + newArr.push(x) + } + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: MapId +// ---------------------------------------------------------------------------- + +function MapIdLargeHoley() { + var newArr = largeHoleyArray.map(x => x); + // basic sanity check + if (newArr.length != largeHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Setup and Run +// ---------------------------------------------------------------------------- + +load('../base.js'); + +var success = true; + +function PrintResult(name, result) { + print(name + '-ArrayLiteralInitialSpreadLargeDoubleHoley(Score): ' + result); +} + +function PrintError(name, error) { + PrintResult('Error: ' + name, error); + success = false; +} + +// Run the benchmark (5 x 100) iterations instead of 1 second. +function CreateBenchmark(name, f) { + new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 5, f) ]); +} + +CreateBenchmark('Spread', SpreadLargeHoley); +CreateBenchmark('ForLength', ForLengthLargeHoley); +CreateBenchmark('ForLengthEmpty', ForLengthEmptyLargeHoley); +CreateBenchmark('Slice', SliceLargeHoley); +CreateBenchmark('Slice0', Slice0LargeHoley); +CreateBenchmark('ConcatReceive', ConcatReceiveLargeHoley); +CreateBenchmark('ConcatArg', ConcatArgLargeHoley); + +BenchmarkSuite.config.doWarmup = true; +BenchmarkSuite.config.doDeterministic = true; +BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError}); diff --git a/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoublePacked/run.js b/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoublePacked/run.js new file mode 100644 index 0000000000..e53fa90e7f --- /dev/null +++ b/test/js-perf-test/ArrayLiteralInitialSpreadLargeDoublePacked/run.js @@ -0,0 +1,151 @@ +// 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. + +// Comparing different copy schemes against spread initial literals. +// Benchmarks for large packed double arrays. + +const largeHoleyArray = new Array(1e5); +const largeArray = Array.from(largeHoleyArray.keys()).map(x => x + 6.66); + +// ---------------------------------------------------------------------------- +// Benchmark: Spread +// ---------------------------------------------------------------------------- + +function SpreadLarge() { + var newArr = [...largeArray]; + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLength +// ---------------------------------------------------------------------------- + +function ForLengthLarge() { + var newArr = new Array(largeArray.length); + for (let i = 0; i < largeArray.length; i++) { + newArr[i] = largeArray[i]; + } + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLengthEmpty +// ---------------------------------------------------------------------------- + +function ForLengthEmptyLarge() { + var newArr = []; + for (let i = 0; i < largeArray.length; i++) { + newArr[i] = largeArray[i]; + } + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice +// ---------------------------------------------------------------------------- + +function SliceLarge() { + var newArr = largeArray.slice(); + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice0 +// ---------------------------------------------------------------------------- + +function Slice0Large() { + var newArr = largeArray.slice(0); + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatReceive +// ---------------------------------------------------------------------------- + +function ConcatReceiveLarge() { + var newArr = largeArray.concat(); + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatArg +// ---------------------------------------------------------------------------- + +function ConcatArgLarge() { + var newArr = [].concat(largeArray); + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForOfPush +// ---------------------------------------------------------------------------- + +function ForOfPushLarge() { + var newArr = []; + for (let x of largeArray) { + newArr.push(x) + } + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: MapId +// ---------------------------------------------------------------------------- + +function MapIdLarge() { + var newArr = largeArray.map(x => x); + // basic sanity check + if (newArr.length != largeArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Setup and Run +// ---------------------------------------------------------------------------- + +load('../base.js'); + +var success = true; + +function PrintResult(name, result) { + print(name + '-ArrayLiteralInitialSpreadLargeDoublePacked(Score): ' + result); +} + +function PrintError(name, error) { + PrintResult('Error: ' + name, error); + success = false; +} + +// Run the benchmark (5 x 100) iterations instead of 1 second. +function CreateBenchmark(name, f) { + new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 5, f) ]); +} + +CreateBenchmark('Spread', SpreadLarge); +CreateBenchmark('ForLength', ForLengthLarge); +CreateBenchmark('ForLengthEmpty', ForLengthEmptyLarge); +CreateBenchmark('Slice', SliceLarge); +CreateBenchmark('Slice0', Slice0Large); +CreateBenchmark('ConcatReceive', ConcatReceiveLarge); +CreateBenchmark('ConcatArg', ConcatArgLarge); + +BenchmarkSuite.config.doWarmup = true; +BenchmarkSuite.config.doDeterministic = true; +BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError}); diff --git a/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoubleHoley/run.js b/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoubleHoley/run.js new file mode 100644 index 0000000000..19768b73aa --- /dev/null +++ b/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoubleHoley/run.js @@ -0,0 +1,159 @@ +// 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. + +// Comparing different copy schemes against spread initial literals. +// Benchmarks for small holey double arrays. + +const smallHoleyArray = Array(100); + +for (var i = 0; i < 10; i++) { + smallHoleyArray[i] = i + 6.66; +} +for (var i = 90; i < 99; i++) { + smallHoleyArray[i] = i + 6.66; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Spread +// ---------------------------------------------------------------------------- + +function SpreadSmallHoley() { + var newArr = [...smallHoleyArray]; + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLength +// ---------------------------------------------------------------------------- + +function ForLengthSmallHoley() { + var newArr = new Array(smallHoleyArray.length); + for (let i = 0; i < smallHoleyArray.length; i++) { + newArr[i] = smallHoleyArray[i]; + } + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLengthEmpty +// ---------------------------------------------------------------------------- + +function ForLengthEmptySmallHoley() { + var newArr = []; + for (let i = 0; i < smallHoleyArray.length; i++) { + newArr[i] = smallHoleyArray[i]; + } + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice +// ---------------------------------------------------------------------------- + +function SliceSmallHoley() { + var newArr = smallHoleyArray.slice(); + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice0 +// ---------------------------------------------------------------------------- + +function Slice0SmallHoley() { + var newArr = smallHoleyArray.slice(0); + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatReceive +// ---------------------------------------------------------------------------- + +function ConcatReceiveSmallHoley() { + var newArr = smallHoleyArray.concat(); + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatArg +// ---------------------------------------------------------------------------- + +function ConcatArgSmallHoley() { + var newArr = [].concat(smallHoleyArray); + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForOfPush +// ---------------------------------------------------------------------------- + +function ForOfPushSmallHoley() { + var newArr = []; + for (let x of smallHoleyArray) { + newArr.push(x) + } + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: MapId +// ---------------------------------------------------------------------------- + +function MapIdSmallHoley() { + var newArr = smallHoleyArray.map(x => x); + // basic sanity check + if (newArr.length != smallHoleyArray.length) throw 666; + return newArr; +} + + +// ---------------------------------------------------------------------------- +// Setup and Run +// ---------------------------------------------------------------------------- + +load('../base.js'); + +var success = true; + +function PrintResult(name, result) { + print(name + '-ArrayLiteralInitialSpreadSmallDoubleHoley(Score): ' + result); +} + +function PrintError(name, error) { + PrintResult('Error: ' + name, error); + success = false; +} + +function CreateBenchmark(name, f) { + new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 0, f) ]); +} + +CreateBenchmark('Spread', SpreadSmallHoley); +CreateBenchmark('ForLength', ForLengthSmallHoley); +CreateBenchmark('ForLengthEmpty', ForLengthEmptySmallHoley); +CreateBenchmark('Slice', SliceSmallHoley); +CreateBenchmark('Slice0', Slice0SmallHoley); +CreateBenchmark('ConcatReceive', ConcatReceiveSmallHoley); +CreateBenchmark('ConcatArg', ConcatArgSmallHoley); +CreateBenchmark('ForOfPush', ForOfPushSmallHoley); +CreateBenchmark('MapId', MapIdSmallHoley); + +BenchmarkSuite.config.doWarmup = true; +BenchmarkSuite.config.doDeterministic = false; +BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError}); diff --git a/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoublePacked/run.js b/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoublePacked/run.js new file mode 100644 index 0000000000..bca629525f --- /dev/null +++ b/test/js-perf-test/ArrayLiteralInitialSpreadSmallDoublePacked/run.js @@ -0,0 +1,154 @@ +// 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. + +// Comparing different copy schemes against spread initial literals. +// Benchmarks for small packed double arrays. + +const smallHoleyArray = Array(100); +const smallArray = Array.from(Array(100).keys()).map(x => x + 6.66);; + +// ---------------------------------------------------------------------------- +// Benchmark: Spread +// ---------------------------------------------------------------------------- + +function SpreadSmall() { + var newArr = [...smallArray]; + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLength +// ---------------------------------------------------------------------------- + +function ForLengthSmall() { + var newArr = new Array(smallArray.length); + for (let i = 0; i < smallArray.length; i++) { + newArr[i] = smallArray[i]; + } + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForLengthEmpty +// ---------------------------------------------------------------------------- + +function ForLengthEmptySmall() { + var newArr = []; + for (let i = 0; i < smallArray.length; i++) { + newArr[i] = smallArray[i]; + } + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice +// ---------------------------------------------------------------------------- + +function SliceSmall() { + var newArr = smallArray.slice(); + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: Slice0 +// ---------------------------------------------------------------------------- + +function Slice0Small() { + var newArr = smallArray.slice(0); + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatReceive +// ---------------------------------------------------------------------------- + +function ConcatReceiveSmall() { + var newArr = smallArray.concat(); + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ConcatArg +// ---------------------------------------------------------------------------- + +function ConcatArgSmall() { + var newArr = [].concat(smallArray); + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: ForOfPush +// ---------------------------------------------------------------------------- + +function ForOfPushSmall() { + var newArr = []; + for (let x of smallArray) { + newArr.push(x) + } + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + +// ---------------------------------------------------------------------------- +// Benchmark: MapId +// ---------------------------------------------------------------------------- + +function MapIdSmall() { + var newArr = smallArray.map(x => x); + // basic sanity check + if (newArr.length != smallArray.length) throw 666; + return newArr; +} + + +// ---------------------------------------------------------------------------- +// Setup and Run +// ---------------------------------------------------------------------------- + +load('../base.js'); + +var success = true; + +function PrintResult(name, result) { + print(name + '-ArrayLiteralInitialSpreadSmallDoublePacked(Score): ' + result); +} + +function PrintError(name, error) { + PrintResult('Error: ' + name, error); + success = false; +} + +function CreateBenchmark(name, f) { + new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 0, f) ]); +} + +CreateBenchmark('Spread', SpreadSmall); +CreateBenchmark('ForLength', ForLengthSmall); +CreateBenchmark('ForLengthEmpty', ForLengthEmptySmall); +CreateBenchmark('Slice', SliceSmall); +CreateBenchmark('Slice0', Slice0Small); +CreateBenchmark('ConcatReceive', ConcatReceiveSmall); +CreateBenchmark('ConcatArg', ConcatArgSmall); +CreateBenchmark('ForOfPush', ForOfPushSmall); +CreateBenchmark('MapId', MapIdSmall); + + +BenchmarkSuite.config.doWarmup = true; +BenchmarkSuite.config.doDeterministic = false; +BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError}); diff --git a/test/js-perf-test/JSTests.json b/test/js-perf-test/JSTests.json index e85176ac50..15e22733d3 100644 --- a/test/js-perf-test/JSTests.json +++ b/test/js-perf-test/JSTests.json @@ -127,6 +127,74 @@ {"name": "ConcatArg"} ] }, + { + "name": "ArrayLiteralInitialSpreadSmallDoublePacked", + "path": ["ArrayLiteralInitialSpreadSmallDoublePacked"], + "main": "run.js", + "resources": [], + "results_regexp": "^%s\\-ArrayLiteralInitialSpreadSmallDoublePacked\\(Score\\): (.+)$", + "tests": [ + {"name": "Spread"}, + {"name": "ForLength"}, + {"name": "ForLengthEmpty"}, + {"name": "Slice"}, + {"name": "Slice0"}, + {"name": "ConcatReceive"}, + {"name": "ConcatArg"}, + {"name": "ForOfPush"}, + {"name": "MapId"} + ] + }, + { + "name": "ArrayLiteralInitialSpreadLargeDoublePacked", + "path": ["ArrayLiteralInitialSpreadLargeDoublePacked"], + "main": "run.js", + "resources": [], + "results_regexp": "^%s\\-ArrayLiteralInitialSpreadLargeDoublePacked\\(Score\\): (.+)$", + "tests": [ + {"name": "Spread"}, + {"name": "ForLength"}, + {"name": "ForLengthEmpty"}, + {"name": "Slice"}, + {"name": "Slice0"}, + {"name": "ConcatReceive"}, + {"name": "ConcatArg"} + ] + }, + { + "name": "ArrayLiteralInitialSpreadSmallDoubleHoley", + "path": ["ArrayLiteralInitialSpreadSmallDoubleHoley"], + "main": "run.js", + "resources": [], + "results_regexp": "^%s\\-ArrayLiteralInitialSpreadSmallDoubleHoley\\(Score\\): (.+)$", + "tests": [ + {"name": "Spread"}, + {"name": "ForLength"}, + {"name": "ForLengthEmpty"}, + {"name": "Slice"}, + {"name": "Slice0"}, + {"name": "ConcatReceive"}, + {"name": "ConcatArg"}, + {"name": "ForOfPush"}, + {"name": "MapId"} + ] + }, + { + "name": "ArrayLiteralInitialSpreadLargeDoubleHoley", + "path": ["ArrayLiteralInitialSpreadLargeDoubleHoley"], + "main": "run.js", + "resources": [], + "results_regexp": "^%s\\-ArrayLiteralInitialSpreadLargeDoubleHoley\\(Score\\): (.+)$", + "tests": [ + {"name": "Spread"}, + {"name": "ForLength"}, + {"name": "ForLengthEmpty"}, + {"name": "Slice"}, + {"name": "Slice0"}, + {"name": "ConcatReceive"}, + {"name": "ConcatArg"} + ] + }, { "name": "ArrayLiteralInitialSpreadSmallSmiMap", "path": ["ArrayLiteralInitialSpreadSmallSmiMap"],