Enable warmup and/or longer runs for ArrayLiteralInitialSpread.

With warmup and/or longer runs, the benchmark results are more reliable.
This CL also splits the benchmark into smaller ones for easier management.

Change-Id: Ieba0734bef841d131b3184938109ca179994e173
Reviewed-on: https://chromium-review.googlesource.com/1188572
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Hai Dang <dhai@google.com>
Cr-Commit-Position: refs/heads/master@{#55422}
This commit is contained in:
Hai Dang 2018-08-27 09:54:04 +02:00 committed by Commit Bot
parent 5f225ebbb7
commit 8c171105df
5 changed files with 627 additions and 419 deletions

View File

@ -1,419 +0,0 @@
// 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
const smallHoleyArray = Array(100);
const smallArray = Array.from(Array(100).keys());
for (var i = 0; i < 10; i++) {
smallHoleyArray[i] = i;
}
for (var i = 90; i < 99; i++) {
smallHoleyArray[i] = i;
}
const largeHoleyArray = new Array(100000);
const largeArray = Array.from(largeHoleyArray.keys());
for (var i = 0; i < 100; i++) {
largeHoleyArray[i] = i;
}
for (var i = 5000; i < 5500; i++) {
largeHoleyArray[i] = i;
}
// ----------------------------------------------------------------------------
// Benchmark: Spread
// ----------------------------------------------------------------------------
function SpreadSmall() {
var newArr = [...smallArray];
// basic sanity check
if (newArr.length != smallArray.length) throw 666;
return newArr;
}
function SpreadLarge() {
var newArr = [...largeArray];
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function SpreadSmallHoley() {
var newArr = [...smallHoleyArray];
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
function SpreadLargeHoley() {
var newArr = [...largeHoleyArray];
// basic sanity check
if (newArr.length != largeHoleyArray.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;
}
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;
}
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;
}
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 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;
}
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;
}
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;
}
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 SliceSmall() {
var newArr = smallArray.slice();
// basic sanity check
if (newArr.length != smallArray.length) throw 666;
return newArr;
}
function SliceLarge() {
var newArr = largeArray.slice();
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function SliceSmallHoley() {
var newArr = smallHoleyArray.slice();
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
function SliceLargeHoley() {
var newArr = largeHoleyArray.slice();
// basic sanity check
if (newArr.length != largeHoleyArray.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;
}
function Slice0Large() {
var newArr = largeArray.slice(0);
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function Slice0SmallHoley() {
var newArr = smallHoleyArray.slice(0);
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
function Slice0LargeHoley() {
var newArr = largeHoleyArray.slice(0);
// basic sanity check
if (newArr.length != largeHoleyArray.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;
}
function ConcatReceiveLarge() {
var newArr = largeArray.concat();
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function ConcatReceiveSmallHoley() {
var newArr = smallHoleyArray.concat();
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
function ConcatReceiveLargeHoley() {
var newArr = largeHoleyArray.concat();
// basic sanity check
if (newArr.length != largeHoleyArray.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;
}
function ConcatArgLarge() {
var newArr = [].concat(largeArray);
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function ConcatArgSmallHoley() {
var newArr = [].concat(smallHoleyArray);
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
function ConcatArgLargeHoley() {
var newArr = [].concat(largeHoleyArray);
// basic sanity check
if (newArr.length != largeHoleyArray.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;
}
function ForOfPushLarge() {
var newArr = [];
for (let x of largeArray) {
newArr.push(x)
}
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function ForOfPushSmallHoley() {
var newArr = [];
for (let x of smallHoleyArray) {
newArr.push(x)
}
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
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 MapIdSmall() {
var newArr = smallArray.map(x => x);
// basic sanity check
if (newArr.length != smallArray.length) throw 666;
return newArr;
}
function MapIdLarge() {
var newArr = largeArray.map(x => x);
// basic sanity check
if (newArr.length != largeArray.length) throw 666;
return newArr;
}
function MapIdSmallHoley() {
var newArr = smallHoleyArray.map(x => x);
// basic sanity check
if (newArr.length != smallHoleyArray.length) throw 666;
return newArr;
}
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 + '-ArrayLiteralInitialSpread(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-Small', SpreadSmall);
CreateBenchmark('ForLength-Small', ForLengthSmall);
CreateBenchmark('ForLengthEmpty-Small', ForLengthEmptySmall);
CreateBenchmark('Slice-Small', SliceSmall);
CreateBenchmark('Slice0-Small', Slice0Small);
CreateBenchmark('ConcatReceive-Small', ConcatReceiveSmall);
CreateBenchmark('ConcatArg-Small', ConcatArgSmall);
CreateBenchmark('ForOfPush-Small', ForOfPushSmall);
CreateBenchmark('MapId-Small', MapIdSmall);
CreateBenchmark('Spread-Large', SpreadLarge);
CreateBenchmark('ForLength-Large', ForLengthLarge);
CreateBenchmark('ForLengthEmpty-Large', ForLengthEmptyLarge);
CreateBenchmark('Slice-Large', SliceLarge);
CreateBenchmark('Slice0-Large', Slice0Large);
CreateBenchmark('ConcatReceive-Large', ConcatReceiveLarge);
CreateBenchmark('ConcatArg-Large', ConcatArgLarge);
CreateBenchmark('ForOfPush-Large', ForOfPushLarge);
CreateBenchmark('MapId-Large', MapIdLarge);
CreateBenchmark('Spread-SmallHoley', SpreadSmallHoley);
CreateBenchmark('ForLength-SmallHoley', ForLengthSmallHoley);
CreateBenchmark('ForLengthEmpty-SmallHoley', ForLengthEmptySmallHoley);
CreateBenchmark('Slice-SmallHoley', SliceSmallHoley);
CreateBenchmark('Slice0-SmallHoley', Slice0SmallHoley);
CreateBenchmark('ConcatReceive-SmallHoley', ConcatReceiveSmallHoley);
CreateBenchmark('ConcatArg-SmallHoley', ConcatArgSmallHoley);
CreateBenchmark('ForOfPush-SmallHoley', ForOfPushSmallHoley);
CreateBenchmark('MapId-SmallHoley', MapIdSmallHoley);
CreateBenchmark('Spread-LargeHoley', SpreadLargeHoley);
CreateBenchmark('ForLength-LargeHoley', ForLengthLargeHoley);
CreateBenchmark('ForLengthEmpty-LargeHoley', ForLengthEmptyLargeHoley);
CreateBenchmark('Slice-LargeHoley', SliceLargeHoley);
CreateBenchmark('Slice0-LargeHoley', Slice0LargeHoley);
CreateBenchmark('ConcatReceive-LargeHoley', ConcatReceiveLargeHoley);
CreateBenchmark('ConcatArg-LargeHoley', ConcatArgLargeHoley);
CreateBenchmark('ForOfPush-LargeHoley', ForOfPushLargeHoley);
CreateBenchmark('MapId-LargeHoley', MapIdLargeHoley);
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,153 @@
// 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 arrays.
const largeHoleyArray = new Array(100000);
const largeArray = Array.from(largeHoleyArray.keys());
// ----------------------------------------------------------------------------
// 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 + '-ArrayLiteralInitialSpreadLarge(Score): ' + result);
}
function PrintError(name, error) {
PrintResult('Error: ' + name, error);
success = false;
}
// Run the benchmark (20 x 100) iterations instead of 1 second.
function CreateBenchmark(name, f) {
new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 20, f) ]);
}
CreateBenchmark('Spread', SpreadLarge);
CreateBenchmark('ForLength', ForLengthLarge);
CreateBenchmark('ForLengthEmpty', ForLengthEmptyLarge);
CreateBenchmark('Slice', SliceLarge);
CreateBenchmark('Slice0', Slice0Large);
CreateBenchmark('ConcatReceive', ConcatReceiveLarge);
CreateBenchmark('ConcatArg', ConcatArgLarge);
CreateBenchmark('ForOfPush', ForOfPushLarge);
CreateBenchmark('MapId', MapIdLarge);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = true;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,161 @@
// 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 arrays.
const largeHoleyArray = new Array(100000);
for (var i = 0; i < 100; i++) {
largeHoleyArray[i] = i;
}
for (var i = 5000; i < 5500; i++) {
largeHoleyArray[i] = i;
}
// ----------------------------------------------------------------------------
// 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 + '-ArrayLiteralInitialSpreadLargeHoley(Score): ' + result);
}
function PrintError(name, error) {
PrintResult('Error: ' + name, error);
success = false;
}
// Run the benchmark (20 x 100) iterations instead of 1 second.
function CreateBenchmark(name, f) {
new BenchmarkSuite(name, [1000], [ new Benchmark(name, false, false, 20, f) ]);
}
CreateBenchmark('Spread', SpreadLargeHoley);
CreateBenchmark('ForLength', ForLengthLargeHoley);
CreateBenchmark('ForLengthEmpty', ForLengthEmptyLargeHoley);
CreateBenchmark('Slice', SliceLargeHoley);
CreateBenchmark('Slice0', Slice0LargeHoley);
CreateBenchmark('ConcatReceive', ConcatReceiveLargeHoley);
CreateBenchmark('ConcatArg', ConcatArgLargeHoley);
CreateBenchmark('ForOfPush', ForOfPushLargeHoley);
CreateBenchmark('MapId', MapIdLargeHoley);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = true;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -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 arrays.
const smallHoleyArray = Array(100);
const smallArray = Array.from(Array(100).keys());
// ----------------------------------------------------------------------------
// 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 + '-ArrayLiteralInitialSpreadSmall(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});

View File

@ -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 arrays.
const smallHoleyArray = Array(100);
for (var i = 0; i < 10; i++) {
smallHoleyArray[i] = i;
}
for (var i = 90; i < 99; i++) {
smallHoleyArray[i] = i;
}
// ----------------------------------------------------------------------------
// 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 + '-ArrayLiteralInitialSpreadSmallHoley(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});