Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,14 @@
// Copyright 2019 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.
function LoadNodeType() {
let node = new d8.dom.Div();
let result = 0;
for (var i = 0; i < 10e5; i++) {
result += node.nodeType;
}
return result;
}
createSuite('nodeType', 1, LoadNodeType, ()=>{});

View File

@ -0,0 +1,19 @@
// Copyright 2019 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('accessor.js');
function PrintResult(name, result) {
console.log(name + '-ApiAccessors(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

104
deps/v8/test/js-perf-test/Array/at.js vendored Normal file
View File

@ -0,0 +1,104 @@
// Copyright 2022 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 array_at_size = 100;
// SMI array
(() => {
const A = new Array(array_at_size);
for (let i = 0; i < A.length; i++) {
A[i] = i;
}
assert(%HasSmiElements(A), "A should have SMI elements for this test");
// Commonly used to get the last item.
function testArrayAtNeg1() {
return A.at(-1);
}
function testArrayAt0() {
return A.at(0);
}
function testArrayAt20() {
return A.at(20);
}
function testArrayAt80() {
return A.at(80);
}
createSuiteWithWarmup("Array.at(-1)-smi", 1, testArrayAtNeg1);
createSuiteWithWarmup("Array.at(0)-smi", 1, testArrayAt0);
createSuiteWithWarmup("Array.at(20)-smi", 1, testArrayAt20);
createSuiteWithWarmup("Array.at(80)-smi", 1, testArrayAt80);
})();
// Double array
(() => {
const A = new Array(array_at_size);
for (let i = 0; i < A.length; i++) {
A[i] = i + 0.5;
}
assert(%HasDoubleElements(A), "A should have Double elements for this test");
// Commonly used to get the last item.
function testArrayAtNeg1() {
return A.at(-1);
}
function testArrayAt0() {
return A.at(0);
}
function testArrayAt20() {
return A.at(20);
}
function testArrayAt80() {
return A.at(80);
}
createSuiteWithWarmup("Array.at(-1)-double", 1, testArrayAtNeg1);
createSuiteWithWarmup("Array.at(0)-double", 1, testArrayAt0);
createSuiteWithWarmup("Array.at(20)-double", 1, testArrayAt20);
createSuiteWithWarmup("Array.at(80)-double", 1, testArrayAt80);
})();
// Object array
(() => {
const A = new Array(array_at_size);
for (let i = 0; i < A.length; i++) {
A[i] = { ["p" + i] : i};
}
assert(%HasObjectElements(A), "A should have Object elements for this test");
// Commonly used to get the last item.
function testArrayAtNeg1() {
return A.at(-1);
}
function testArrayAt0() {
return A.at(0);
}
function testArrayAt20() {
return A.at(20);
}
function testArrayAt80() {
return A.at(80);
}
createSuiteWithWarmup("Array.at(-1)-object", 1, testArrayAtNeg1);
createSuiteWithWarmup("Array.at(0)-object", 1, testArrayAt0);
createSuiteWithWarmup("Array.at(20)-object", 1, testArrayAt20);
createSuiteWithWarmup("Array.at(80)-object", 1, testArrayAt80);
})();

View File

@ -0,0 +1,43 @@
// 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 kArraySize = 1000;
const kQuarterSize = kArraySize / 4;
let array = [];
// Copy a quarter of the elements from the middle to the front.
function CopyWithin() {
return new Function(
'array.copyWithin(0, kQuarterSize * 2, kQuarterSize * 3);');
}
createSuite('SmiCopyWithin', 1000, CopyWithin, SmiCopyWithinSetup);
createSuite('StringCopyWithin', 1000, CopyWithin, StringCopyWithinSetup);
createSuite('SparseSmiCopyWithin', 1000, CopyWithin, SparseSmiCopyWithinSetup);
createSuite(
'SparseStringCopyWithin', 1000, CopyWithin, SparseStringCopyWithinSetup);
function SmiCopyWithinSetup() {
array = [];
for (let i = 0; i < kArraySize; ++i) array[i] = i;
}
function StringCopyWithinSetup() {
array = [];
for (let i = 0; i < kArraySize; ++i) array[i] = `Item no. ${i}`;
}
function SparseSmiCopyWithinSetup() {
array = [];
for (let i = 0; i < kArraySize; i += 10) array[i] = i;
}
function SparseStringCopyWithinSetup() {
array = [];
for (let i = 0; i < kArraySize; i += 10) array[i] = `Item no. ${i}`;
}
})();

View File

@ -0,0 +1,37 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastEvery(multiple) {
// Use of variable multiple in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.every((v, i, a) => multiple === 3);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastEvery);
function OptFastEvery() { RunOptFastEvery(3); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableEvery() {
result = array.every(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['DoubleEvery', newClosure('every'), DoubleSetup, v => v > 0.0],
['SmiEvery', newClosure('every'), SmiSetup, v => v != 34343],
['FastEvery', newClosure('every'), FastSetup, v => v !== 'hi'],
['OptFastEvery', OptFastEvery, FastSetup, v => true],
['OptUnreliableEvery', OptUnreliableEvery, FastSetup, v => true]
]);
})();

View File

@ -0,0 +1,72 @@
// Copyright 2017 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.
(() => {
// From the lodash implementation.
function NaiveFilter() {
let index = -1
let resIndex = 0
const length = array == null ? 0 : array.length
const result = []
while (++index < length) {
const value = array[index]
if (func(value, index, array)) {
result[resIndex++] = value
}
}
return result
}
function NaiveFilterSetup() {
// Prime NaiveFilter with polymorphic cases.
array = [1, 2, 3];
NaiveFilter();
NaiveFilter();
array = [3.4]; NaiveFilter();
array = new Array(10); array[0] = 'hello'; NaiveFilter();
SmiSetup();
delete array[1];
}
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastFilter(multiple) {
// Use of variable multiple in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.filter((v, i, a) => multiple === 3);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastFilter);
function OptFastFilter() { RunOptFastFilter(3); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableFilter() {
result = array.filter(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['NaiveFilterReplacement', NaiveFilter, NaiveFilterSetup, v => true],
[
'DoubleFilter', newClosure('filter'), DoubleSetup,
v => Math.floor(v) % 2 === 0
],
['SmiFilter', newClosure('filter'), SmiSetup, v => v % 2 === 0],
['FastFilter', newClosure('filter'), FastSetup, (_, i) => i % 2 === 0],
[
'GenericFilter', newClosure('filter', true), ObjectSetup,
(_, i) => i % 2 === 0
],
['OptFastFilter', OptFastFilter, FastSetup, undefined],
['OptUnreliableFilter', OptUnreliableFilter, FastSetup, v => true]
]);
})();

View File

@ -0,0 +1,72 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFast(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.findIndex((v, i, a) => v === value);
}
// Don't optimize because I want to optimize RunOptFast with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFast);
function OptFast() { RunOptFast(max_index_value); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliable() {
result = array.findIndex(func, side_effect(array));
}
function Naive() {
let index = -1;
const length = array == null ? 0 : array.length;
for (let index = 0; index < length; index++) {
const value = array[index];
if (func(value, index, array)) {
result = value;
break;
}
}
}
function NaiveSetup() {
// Prime Naive with polymorphic cases.
array = [1, 2, 3];
Naive();
Naive();
array = [3.4]; Naive();
array = new Array(10); array[0] = 'hello'; Naive();
SmiSetup();
delete array[1];
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['NaiveFindIndexReplacement', Naive, NaiveSetup, v => v === max_index],
[
'DoubleFindIndex', newClosure('findIndex'), DoubleSetup,
v => v === max_index + 0.5
],
['SmiFindIndex', newClosure('findIndex'), SmiSetup, v => v === max_index],
[
'FastFindIndex', newClosure('findIndex'), FastSetup,
v => v === max_index_value
],
[
'GenericFindIndex', newClosure('findIndex', true), ObjectSetup,
v => v === max_index
],
['OptFastFindIndex', OptFast, FastSetup, undefined],
['OptUnreliableFindIndex', OptUnreliable, FastSetup, v => v === max_index]
]);
})();

63
deps/v8/test/js-perf-test/Array/find.js vendored Normal file
View File

@ -0,0 +1,63 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFast(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.find((v, i, a) => v === value);
}
// Don't optimize because I want to optimize RunOptFast with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFast);
function OptFast() { RunOptFast(max_index_value); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliable() {
result = array.find(func, side_effect(array));
}
function Naive() {
let index = -1;
const length = array == null ? 0 : array.length;
for (let index = 0; index < length; index++) {
const value = array[index];
if (func(value, index, array)) {
result = value;
break;
}
}
}
function NaiveSetup() {
// Prime Naive with polymorphic cases.
array = [1, 2, 3];
Naive();
Naive();
array = [3.4]; Naive();
array = new Array(10); array[0] = 'hello'; Naive();
SmiSetup();
delete array[1];
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['NaiveFindReplacement', Naive, NaiveSetup, v => v === max_index],
['DoubleFind', newClosure('find'), DoubleSetup, v => v === max_index + 0.5],
['SmiFind', newClosure('find'), SmiSetup, v => v === max_index],
['FastFind', newClosure('find'), FastSetup, v => v === max_index_value],
['GenericFind', newClosure('find', true), ObjectSetup, v => v === max_index],
['OptFastFind', OptFast, FastSetup, undefined],
['OptUnreliableFind', OptUnreliable, FastSetup, v => v === max_index]
]);
})();

View File

@ -0,0 +1,74 @@
// 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.
(() => {
function Naive() {
let index = -1;
const length = array == null ? 0 : array.length;
for (let index = 0; index < length; index++) {
const value = array[index];
if (func(value, index, array)) {
result = value;
break;
}
}
}
function NaiveSetup() {
// Prime Naive with polymorphic cases.
array = [1, 2, 3];
Naive();
Naive();
array = [3.4]; Naive();
array = new Array(10); array[0] = 'hello'; Naive();
SmiSetup();
delete array[1];
}
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFast(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.forEach((v, i, a) => v === value);
}
// Don't optimize because I want to optimize RunOptFast with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFast);
function OptFast() { RunOptFast(max_index_value); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliable() {
result = array.forEach(func, side_effect(array));
}
DefineHigherOrderTests([
['NaiveForEachReplacement', Naive, NaiveSetup, v => v === max_index],
[
'DoubleForEach', newClosure('forEach'), DoubleSetup,
v => v === max_index + 0.5
],
['SmiForEach', newClosure('forEach'), SmiSetup, v => v === max_index],
[
'FastForEach', newClosure('forEach'), FastSetup,
v => v === max_index_value
],
[
'GenericForEach', newClosure('forEach', true), ObjectSetup,
v => v === max_index
],
['OptFastForEach', OptFast, FastSetup, undefined],
[
'OptUnreliableForEach', OptUnreliable, FastSetup,
v => v === max_index_value
]
]);
})();

225
deps/v8/test/js-perf-test/Array/from.js vendored Normal file
View File

@ -0,0 +1,225 @@
// 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.
(() => {
createSuite('MixedFrom', 1000, MixedFrom, MixedFromSetup);
createSuite(
'MixedCowNoMapFrom', 1000, MixedCowNoMapFrom, MixedCowNoMapFromSetup);
createSuite('MixedNonCowNoMapFrom', 1000, MixedNonCowNoMapFrom,
MixedNonCowNoMapFromSetup);
createSuite('SmiFrom', 1000, SmiFrom, SmiFromSetup);
createSuite('SmallSmiFrom', 1000, SmallSmiFrom, SmallSmiFromSetup);
createSuite('SmiCowNoMapFrom', 1000, SmiCowNoMapFrom, SmiCowNoMapFromSetup);
createSuite(
'SmiNonCowNoMapFrom', 1000, SmiNonCowNoMapFrom, SmiNonCowNoMapFromSetup);
createSuite(
'SmiNoIteratorFrom', 1000, SmiNoIteratorFrom, SmiNoIteratorFromSetup);
createSuite(
'TransplantedFrom', 1000, TransplantedFrom, TransplantedFromSetup);
createSuite('DoubleFrom', 1000, DoubleFrom, DoubleFromSetup);
createSuite('DoubleNoMapFrom', 1000, DoubleNoMapFrom, DoubleNoMapFromSetup);
createSuite('StringFrom', 1000, StringFrom, StringFromSetup);
createSuite(
'StringCowNoMapFrom', 1000, StringCowNoMapFrom, StringCowNoMapFromSetup);
createSuite('StringNonCowNoMapFrom', 1000, StringNonCowNoMapFrom,
StringNonCowNoMapFromSetup);
function ArrayLike() {}
ArrayLike.from = Array.from;
var arg
var result;
var func
// This creates a COW array of smis. COWness does not affect the performance
// of Array.from calls with a callback function.
var smi_array_Cow = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
];
// This creates a non-COW array.
var smi_array = Array.from(smi_array_Cow);
smi_array[0] = 1;
// This creates an array of doubles. There is no COW array for doubles.
var double_array = [
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, //
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, //
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, //
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, //
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, //
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
];
// This creates a COW array of objects.
var string_array_Cow = [
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b',
'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b',
'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b',
'c', 'a', 'b', 'c', 'a', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
];
// This creates a non-COW array.
var string_array = Array.from(string_array_Cow);
string_array[0] = 'a';
// This creates a COW array of objects.
var mixed_array_Cow = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, //
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, //
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, //
1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5, //
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a',
];
// This creates a non-COW array.
var mixed_array = Array.from(mixed_array_Cow);
mixed_array[0] = 1;
// Although these functions have the same code, they are separated for
// clean IC feedback.
function SmallSmiFrom() {
result = Array.from(arg, func);
}
function SmiCowNoMapFrom() {
result = Array.from(arg);
}
function SmiNonCowNoMapFrom() {
result = Array.from(arg);
}
function SmiFrom() {
result = Array.from(arg, func);
}
function SmiNoIteratorFrom() {
result = Array.from(arg, func);
}
function TransplantedFrom() {
result = ArrayLike.from(arg, func);
}
function DoubleFrom() {
result = Array.from(arg, func);
}
function DoubleNoMapFrom() {
result = Array.from(arg);
}
function StringFrom() {
result = Array.from(arg, func);
}
function StringCowNoMapFrom() {
result = Array.from(arg);
}
function StringNonCowNoMapFrom() {
result = Array.from(arg);
}
function MixedFrom() {
result = Array.from(arg, func);
}
function MixedCowNoMapFrom() {
result = Array.from(arg);
}
function MixedNonCowNoMapFrom() {
result = Array.from(arg);
}
function SmallSmiFromSetup() {
func = (v, i) => v + i;
arg = [1, 2, 3];
}
function SmiCowNoMapFromSetup() {
func = undefined;
arg = smi_array_Cow;
}
function SmiNonCowNoMapFromSetup() {
func = undefined;
arg = smi_array;
}
function SmiFromSetup() {
func = (v, i) => v + i;
arg = smi_array_Cow;
}
function SmiNoIteratorFromSetup() {
func = (v, i) => v + i;
array = smi_array_Cow;
arg = {length: array.length};
Object.assign(arg, array);
}
function TransplantedFromSetup() {
func = (v, i) => v + i;
arg = smi_array_Cow;
}
function DoubleFromSetup() {
func = (v, i) => v + i;
arg = double_array;
}
function DoubleNoMapFromSetup() {
func = undefined;
arg = double_array;
}
function StringFromSetup() {
func = (v, i) => v + i;
arg = string_array_Cow;
}
function StringCowNoMapFromSetup() {
func = undefined;
arg = string_array_Cow;
}
function StringNonCowNoMapFromSetup() {
func = undefined;
arg = string_array;
}
function MixedFromSetup() {
func = (v, i) => v + i;
arg = mixed_array_Cow;
}
function MixedCowNoMapFromSetup() {
func = undefined;
arg = mixed_array_Cow;
}
function MixedNonCowNoMapFromSetup() {
func = undefined;
arg = mixed_array;
}
})();

36
deps/v8/test/js-perf-test/Array/join.js vendored Normal file
View File

@ -0,0 +1,36 @@
// Copyright 2017 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.
(() => {
var array;
var result;
var array_size = 1000;
function make_join() {
return new Function('result = array.join();');
}
createSuite('SmiJoin', 1000, make_join(), SmiJoinSetup);
createSuite('StringJoin', 1000, make_join(), StringJoinSetup);
createSuite('SparseSmiJoin', 1000, make_join(), SparseSmiJoinSetup);
createSuite('SparseStringJoin', 1000, make_join(), SparseStringJoinSetup);
function SmiJoinSetup() {
array = new Array();
for (var i = 0; i < array_size; ++i) array[i] = i;
}
function StringJoinSetup() {
array = new Array();
for (var i = 0; i < array_size; ++i) array[i] = `Item no. ${i}`;
}
function SparseSmiJoinSetup() {
SmiJoinSetup();
array.length = array.length * 2;
}
function SparseStringJoinSetup() {
StringJoinSetup();
array.length = array.length * 2;
}
})();

63
deps/v8/test/js-perf-test/Array/map.js vendored Normal file
View File

@ -0,0 +1,63 @@
// Copyright 2017 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.
(() => {
function NaiveMap() {
let index = -1
const length = array == null ? 0 : array.length
const result = new Array(length)
while (++index < length) {
result[index] = func(array[index], index, array)
}
return result
}
function NaiveMapSetup() {
// Prime NaiveMap with polymorphic cases.
array = [1, 2, 3];
NaiveMap();
NaiveMap();
array = [3.4]; NaiveMap();
array = new Array(10); array[0] = 'hello'; NaiveMap();
SmiSetup();
delete array[1];
}
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastMap(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.map((v, i, a) => v + value);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastMap);
function OptFastMap() { RunOptFastMap(" 3"); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableMap() {
result = array.map(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['NaiveMapReplacement', NaiveMap, NaiveMapSetup, v => v],
['SmiMap', newClosure('map'), SmiSetup, v => v],
['DoubleMap', newClosure('map'), DoubleSetup, v => v],
['FastMap', newClosure('map'), FastSetup, v => v],
['SmallSmiToDoubleMap', newClosure('map'), SmiSetup, v => v + 0.5],
['SmallSmiToFastMap', newClosure('map'), SmiSetup, v => 'hi' + v],
['GenericMap', newClosure('map', true), ObjectSetup, v => v],
['OptFastMap', OptFastMap, FastSetup, undefined],
['OptUnreliableMap', OptUnreliableMap, FastSetup, v => v]
]);
})();

121
deps/v8/test/js-perf-test/Array/of.js vendored Normal file
View File

@ -0,0 +1,121 @@
// 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.
(() => {
createSuite('EmptyArrayOf', 1000, EmptyArrayOf, EmptyArrayOfSetup);
createSuite(
'SmallTransplantedArrayOf', 1000, SmallTransplantedArrayOf,
SmallTransplantedArrayOfSetup);
createSuite('SmallSmiArrayOf', 1000, SmallSmiArrayOf, SmallSmiArrayOfSetup);
createSuite('LargeSmiArrayOf', 1000, LargeSmiArrayOf, LargeSmiArrayOfSetup);
createSuite(
'SmallDoubleArrayOf', 1000, SmallDoubleArrayOf, SmallDoubleArrayOfSetup);
createSuite(
'SmallStringArrayOf', 1000, SmallStringArrayOf, SmallStringArrayOfSetup);
createSuite(
'SmallMixedArrayOf', 1000, SmallMixedArrayOf, SmallMixedArrayOfSetup);
function ArrayLike() {}
ArrayLike.of = Array.of;
var arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
var arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20
var result;
function EmptyArrayOf() {
result = Array.of();
}
function BaselineArray() {
result = [arg1, arg2, arg3];
}
function SmallSmiArrayOf() {
result = Array.of(arg1, arg2, arg3);
}
function LargeSmiArrayOf() {
result = Array.of(
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20);
}
function SmallTransplantedArrayOf() {
result = ArrayLike.of(arg1, arg2, arg3);
}
function SmallDoubleArrayOf() {
result = Array.of(arg1, arg2, arg3);
}
function SmallStringArrayOf() {
result = Array.of(arg1, arg2, arg3);
}
function SmallMixedArrayOf() {
result = Array.of(arg1, arg2, arg3);
}
function EmptyArrayOfSetup() {}
function BaselineArraySetup() {
arg1 = 1;
arg2 = 2;
arg3 = 3;
}
function SmallSmiArrayOfSetup() {
arg1 = 1;
arg2 = 2;
arg3 = 3;
}
function SmallTransplantedArrayOfSetup() {
arg1 = 1;
arg2 = 2;
arg3 = 3;
}
function SmallDoubleArrayOfSetup() {
arg1 = 1.5;
arg2 = 2.5;
arg3 = 3.5;
}
function SmallStringArrayOfSetup() {
arg1 = 'cat';
arg2 = 'dog';
arg3 = 'giraffe';
}
function SmallMixedArrayOfSetup() {
arg1 = 1;
arg2 = 2.5;
arg3 = 'giraffe';
}
function LargeSmiArrayOfSetup() {
arg1 = 1;
arg2 = 2;
arg3 = 3;
arg4 = 4;
arg5 = 5;
arg6 = 6;
arg7 = 7;
arg8 = 8;
arg9 = 9;
arg10 = 10;
arg11 = 11;
arg12 = 12;
arg13 = 13;
arg14 = 14;
arg15 = 15;
arg16 = 16;
arg17 = 17;
arg18 = 18;
arg19 = 19;
arg20 = 20;
}
})();

View File

@ -0,0 +1,48 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastReduceRight(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.reduceRight((p, v, i, a) => p + value);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastReduceRight);
function OptFastReduceRight() { RunOptFastReduceRight("3"); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableReduceRight() {
result = array.reduceRight(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
[
'DoubleReduceRight', newClosure('reduceRight'), DoubleSetup,
(p, v, i, o) => p + v
],
[
'SmiReduceRight', newClosure('reduceRight'), SmiSetup, (p, v, i, a) => p + 1
],
[
'FastReduceRight', newClosure('reduceRight'), FastSetup,
(p, v, i, a) => p + v
],
['OptFastReduceRight', OptFastReduceRight, FastSetup, undefined],
[
'OptUnreliableReduceRight', OptUnreliableReduceRight, FastSetup,
(p, v, i, a) => p + v
]
]);
})();

View File

@ -0,0 +1,39 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastReduce(value) {
// Use of variable {value} in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.reduce((p, v, i, a) => p + value);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastReduce);
function OptFastReduce() { RunOptFastReduce("3"); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableReduce() {
result = array.reduce(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['DoubleReduce', newClosure('reduce'), DoubleSetup, (p, v, i, o) => p + v],
['SmiReduce', newClosure('reduce'), SmiSetup, (p, v, i, a) => p + 1],
['FastReduce', newClosure('reduce'), FastSetup, (p, v, i, a) => p + v],
['OptFastReduce', OptFastReduce, FastSetup, undefined],
[
'OptUnreliableReduce', OptUnreliableReduce, FastSetup, (p, v, i, a) => p = v
]
]);
})();

165
deps/v8/test/js-perf-test/Array/run.js vendored Normal file
View File

@ -0,0 +1,165 @@
// Copyright 2014 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.
d8.file.execute('../base.js');
let array;
// Initialize func variable to ensure the first test doesn't benefit from
// global object property tracking.
let func = 0;
let this_arg;
let result;
const array_size = 100;
const max_index = array_size - 1;
// Matches what {FastSetup} below produces.
const max_index_value = `value ${max_index}`;
// newClosure is a handy function to get a fresh
// closure unpolluted by IC feedback for a 2nd-order array builtin
// test.
function newClosure(name, generic = false) {
if (generic) {
return new Function(
`result = Array.prototype.${name}.call(array, func, this_arg);`);
}
return new Function(`result = array.${name}(func, this_arg);`);
}
function MakeHoley(array) {
for (let i =0; i < array.length; i+=2) {
delete array[i];
}
assert(%HasHoleyElements(array));
}
function SmiSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(i);
// TODO(v8:10105): May still create holey arrays (allocation sites?).
// assert(%HasFastPackedElements(array));
assert(%HasSmiElements(array));
}
function HoleySmiSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(i);
MakeHoley(array);
assert(%HasSmiElements(array));
}
function DoubleSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(i + 0.5);
// TODO(v8:10105): May still create holey arrays (allocation sites?).
// assert(%HasFastPackedElements(array));
assert(%HasDoubleElements(array));
}
function HoleyDoubleSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(i + 0.5);
MakeHoley(array);
assert(%HasDoubleElements(array));
}
function FastSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(`value ${i}`);
// TODO(v8:10105): May still create holey arrays (allocation sites?).
// assert(%HasFastPackedElements(array));
assert(%HasObjectElements(array));
}
function HoleyFastSetup() {
array = [];
for (let i = 0; i < array_size; i++) array.push(`value ${i}`);
MakeHoley(array);
assert(%HasObjectElements(array));
}
function DictionarySetup() {
array = [];
// Add a large index to force dictionary elements.
array[2**30] = 10;
// Spread out {array_size} elements.
for (var i = 0; i < array_size-1; i++) {
array[i*101] = i;
}
assert(%HasDictionaryElements(array));
}
function ObjectSetup() {
array = { length: array_size };
for (var i = 0; i < array_size; i++) {
array[i] = i;
}
assert(%HasObjectElements(array));
assert(%HasHoleyElements(array));
}
const ARRAY_SETUP = {
PACKED_SMI: SmiSetup,
HOLEY_SMI: HoleySmiSetup,
PACKED_DOUBLE: DoubleSetup,
HOLEY_DOUBLE: HoleyDoubleSetup,
PACKED: FastSetup,
HOLEY: HoleyFastSetup,
DICTIONARY: DictionarySetup,
}
function DefineHigherOrderTests(tests) {
let i = 0;
while (i < tests.length) {
const [name, testFunc, setupFunc, callback] = tests[i++];
let setupFuncWrapper = () => {
func = callback;
this_arg = undefined;
setupFunc();
};
createSuite(name, 1000, testFunc, setupFuncWrapper);
}
}
// Higher-order Array builtins.
d8.file.execute('filter.js');
d8.file.execute('map.js');
d8.file.execute('every.js');
d8.file.execute('some.js');
d8.file.execute('for-each.js');
d8.file.execute('reduce.js');
d8.file.execute('reduce-right.js');
d8.file.execute('find.js');
d8.file.execute('find-index.js');
// Other Array builtins.
d8.file.execute('from.js');
d8.file.execute('of.js');
d8.file.execute('join.js');
d8.file.execute('to-string.js');
d8.file.execute('slice.js');
d8.file.execute('copy-within.js');
d8.file.execute('at.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Array(Score): ' + result);
}
function PrintStep(name) {}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });

211
deps/v8/test/js-perf-test/Array/slice.js vendored Normal file
View File

@ -0,0 +1,211 @@
// 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 kArraySize = 1000;
(() => {
const A = new Array(kArraySize);
for (let i = 0; i < A.length; i++) {
A[i] = i;
}
assert(%HasSmiElements(A), "A should have SMI elements for this test");
// Commonly used to copy.
function testArraySlice0() {
return A.slice(0);
}
function testArraySlice500() {
return A.slice(500);
}
function testArraySlice500_999() {
return A.slice(500, 999);
}
function testArraySliceN500() {
return A.slice(-500);
}
function testArraySlice200_700() {
return A.slice(200, 700);
}
function testArraySlice200_N300() {
return A.slice(200, -300);
}
function testArraySlice4_1() {
return A.slice(200, -300);
}
createSuiteWithWarmup("Array.slice(0)", 1, testArraySlice0);
createSuiteWithWarmup("Array.slice(500)", 1, testArraySlice500);
createSuiteWithWarmup("Array.slice(500,999)", 1, testArraySlice500_999);
createSuiteWithWarmup("Array.slice(-500)", 1, testArraySliceN500);
createSuiteWithWarmup("Array.slice(200,700)", 1, testArraySlice200_700);
createSuiteWithWarmup("Array.slice(200,-300)", 1, testArraySlice200_N300);
createSuiteWithWarmup("Array.slice(4,1)", 1, testArraySlice4_1);
})();
(() => {
const A = new Array(kArraySize);
for (let i = 0; i < A.length; i++) {
A[i] = i;
}
A[100000] = 255;
assert(%HasDictionaryElements(A), "A should be in dictionary mode for this test");
function testArraySlice0() {
return A.slice(0);
}
function testArraySlice500_999() {
return A.slice(500, 999);
}
function testArraySlice200_700() {
return A.slice(200, 700);
}
function testArraySlice200_N300() {
return A.slice(200, -300);
}
function testArraySlice4_1() {
return A.slice(200, -300);
}
createSuiteWithWarmup("Array.slice(0)-dict", 1, testArraySlice0);
createSuiteWithWarmup("Array.slice(500,999)-dict", 1, testArraySlice500_999);
createSuiteWithWarmup("Array.slice(200,700)-dict", 1, testArraySlice200_700);
createSuiteWithWarmup("Array.slice(200,-300)-dict", 1, testArraySlice200_N300);
createSuiteWithWarmup("Array.slice(4,1)-dict", 1, testArraySlice4_1);
})();
(() => {
const A = new Array(kArraySize);
for (let i = 0; i < A.length; i++) {
A[i] = i + 0.5;
}
assert(%HasDoubleElements(A), "A should have double elements for this test");
function testArraySlice0() {
return A.slice(0);
}
function testArraySlice500_999() {
return A.slice(500, 999);
}
function testArraySlice200_700() {
return A.slice(200, 700);
}
function testArraySlice200_N300() {
return A.slice(200, -300);
}
function testArraySlice4_1() {
return A.slice(200, -300);
}
createSuiteWithWarmup("Array.slice(0)-double", 1, testArraySlice0);
createSuiteWithWarmup("Array.slice(500,999)-double", 1, testArraySlice500_999);
createSuiteWithWarmup("Array.slice(200,700)-double", 1, testArraySlice200_700);
createSuiteWithWarmup("Array.slice(200,-300)-double", 1, testArraySlice200_N300);
createSuiteWithWarmup("Array.slice(4,1)-double", 1, testArraySlice4_1);
})();
(() => {
const A = new Array(kArraySize);
for (let i = 0; i < A.length; i++) {
A[i] = new Object();
}
assert(%HasObjectElements(A), "A should have object elements for this test");
function testArraySlice0() {
return A.slice(0);
}
function testArraySlice500_999() {
return A.slice(500, 999);
}
function testArraySlice200_700() {
return A.slice(200, 700);
}
function testArraySlice200_N300() {
return A.slice(200, -300);
}
function testArraySlice4_1() {
return A.slice(200, -300);
}
createSuiteWithWarmup("Array.slice(0)-object", 1, testArraySlice0);
createSuiteWithWarmup("Array.slice(500,999)-object", 1, testArraySlice500_999);
createSuiteWithWarmup("Array.slice(200,700)-object", 1, testArraySlice200_700);
createSuiteWithWarmup("Array.slice(200,-300)-object", 1, testArraySlice200_N300);
createSuiteWithWarmup("Array.slice(4,1)-object", 1, testArraySlice4_1);
})();
(() => {
const A = new Array(kArraySize);
for (let i = 0; i < A.length; i++) {
A[i] = i;
}
assert(%HasSmiElements(A), "A should have SMI elements for this test");
let arguments_array;
function sloppy_aliased(a) {
arguments_array = arguments;
}
sloppy_aliased.apply(null, A);
assert(%HasSloppyArgumentsElements(arguments_array),
"arguments_array should have sloppy arguments elements for this test");
function testArraySlice0() {
return Array.prototype.slice.call(arguments_array, 0);
}
function testArraySlice500_999() {
return Array.prototype.slice.call(arguments_array, 500, 999);
}
function testArraySlice200_700() {
return Array.prototype.slice.call(arguments_array, 200, 700);
}
function testArraySlice200_N300() {
return Array.prototype.slice.call(arguments_array, 200, -300);
}
function testArraySlice4_1() {
return Array.prototype.slice.call(arguments_array, 200, -300);
}
createSuiteWithWarmup("Array.slice(0)-sloppy-args", 1, testArraySlice0);
createSuiteWithWarmup("Array.slice(500,999)-sloppy-args", 1, testArraySlice500_999);
createSuiteWithWarmup("Array.slice(200,700)-sloppy-args", 1, testArraySlice200_700);
createSuiteWithWarmup("Array.slice(200,-300)-sloppy-args", 1, testArraySlice200_N300);
createSuiteWithWarmup("Array.slice(4,1)-sloppy-args", 1, testArraySlice4_1);
})();

37
deps/v8/test/js-perf-test/Array/some.js vendored Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2017 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.
(() => {
// Make sure we inline the callback, pick up all possible TurboFan
// optimizations.
function RunOptFastSome(multiple) {
// Use of variable multiple in the callback function forces
// context creation without escape analysis.
//
// Also, the arrow function requires inlining based on
// SharedFunctionInfo.
result = array.some((v, i, a) => multiple !== 3);
}
// Don't optimize because I want to optimize RunOptFastMap with a parameter
// to be used in the callback.
%NeverOptimizeFunction(OptFastSome);
function OptFastSome() { RunOptFastSome(3); }
function side_effect(a) { return a; }
%NeverOptimizeFunction(side_effect);
function OptUnreliableSome() {
result = array.some(func, side_effect(array));
}
DefineHigherOrderTests([
// name, test function, setup function, user callback
['DoubleSome', newClosure('some'), DoubleSetup, v => v < 0.0],
['SmiSome', newClosure('some'), SmiSetup, v => v === 34343],
['FastSome', newClosure('some'), FastSetup, v => v === 'hi'],
['OptFastSome', OptFastSome, FastSetup, undefined],
['OptUnreliableSome', OptUnreliableSome, FastSetup, v => v === 'hi']
]);
})();

View File

@ -0,0 +1,40 @@
// Copyright 2017 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.
(() => {
function make_tostring() {
return new Function("result = array.toString();");
}
createSuite('SmiToString', 1000, make_tostring(), SmiToStringSetup);
createSuite('StringToString', 1000, make_tostring(), StringToStringSetup);
createSuite('SparseSmiToString', 1000, make_tostring(), SparseSmiToStringSetup);
createSuite(
'SparseStringToString', 1000, make_tostring(), SparseStringToStringSetup);
var array;
var result;
var array_size = 1000;
function SmiToStringSetup() {
array = new Array();
for (var i = 0; i < array_size; ++i) array[i] = i;
}
function StringToStringSetup() {
array = new Array();
for (var i = 0; i < array_size; ++i) array[i] = `Item no. ${i}`;
}
function SparseSmiToStringSetup() {
SmiToStringSetup();
array.length = array.length * 2;
}
function SparseStringToStringSetup() {
StringToStringSetup();
array.length = array.length * 2;
}
})();

View File

@ -0,0 +1,245 @@
// Copyright 2019 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.
// Compare `in` operator on different types of arrays.
const size = 1e5;
let packed_smi = [];
let packed_double = [];
let packed_elements = [];
let holey_smi = new Array(size);
let holey_double = new Array(size);
let holey_elements = new Array(size);
let sparse_smi = new Array(size);
let sparse_double = new Array(size);
let sparse_elements = new Array(size);
let typed_uint8 = new Uint8Array(size);
let typed_int32 = new Int32Array(size);
let typed_float = new Float64Array(size);
for (let i = 0; i < size; ++i) {
packed_smi[i] = i;
packed_double[i] = i + 0.1;
packed_elements[i] = "" + i;
holey_smi[i] = i;
holey_double[i] = i + 0.1;
holey_elements[i] = "" + i;
typed_uint8[i] = i % 0x100;
typed_int32[i] = i;
typed_float[i] = i + 0.1;
}
let sparse = 0;
for (let i = 0; i < size; i += 100) {
++sparse;
sparse_smi[i] = i;
sparse_double[i] = i + 0.1;
sparse_elements[i] = "" + i;
}
// ----------------------------------------------------------------------------
// Benchmark: Packed SMI
// ----------------------------------------------------------------------------
function PackedSMI() {
let cnt = 0;
let ary = packed_smi;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Packed Double
// ----------------------------------------------------------------------------
function PackedDouble() {
let cnt = 0;
let ary = packed_double;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Packed Elements
// ----------------------------------------------------------------------------
function PackedElements() {
let cnt = 0;
let ary = packed_elements;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Holey SMI
// ----------------------------------------------------------------------------
function HoleySMI() {
let cnt = 0;
let ary = holey_smi;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Holey Double
// ----------------------------------------------------------------------------
function HoleyDouble() {
let cnt = 0;
let ary = holey_double;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Holey Elements
// ----------------------------------------------------------------------------
function HoleyElements() {
let cnt = 0;
let ary = holey_elements;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Sparse SMI
// ----------------------------------------------------------------------------
function SparseSMI() {
let cnt = 0;
let ary = sparse_smi;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != sparse) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Sparse Double
// ----------------------------------------------------------------------------
function SparseDouble() {
let cnt = 0;
let ary = sparse_double;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != sparse) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Sparse Elements
// ----------------------------------------------------------------------------
function SparseElements() {
let cnt = 0;
let ary = sparse_elements;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != sparse) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Typed Uint8
// ----------------------------------------------------------------------------
function TypedUint8() {
let cnt = 0;
let ary = typed_uint8;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Typed Int32
// ----------------------------------------------------------------------------
function TypedInt32() {
let cnt = 0;
let ary = typed_int32;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Typed Float64
// ----------------------------------------------------------------------------
function TypedFloat64() {
let cnt = 0;
let ary = typed_float;
for (let i = 0; i < ary.length; ++i) {
if (i in ary) ++cnt;
}
if (cnt != size) throw 666;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayInOperator(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, 5, f) ]);
}
CreateBenchmark('PackedSMI', PackedSMI);
CreateBenchmark('PackedDouble', PackedDouble);
CreateBenchmark('PackedElements', PackedElements);
CreateBenchmark('HoleySMI', HoleySMI);
CreateBenchmark('HoleyDouble', HoleyDouble);
CreateBenchmark('HoleyElements', HoleyElements);
CreateBenchmark('SparseSMI', SparseSMI);
CreateBenchmark('SparseDouble', SparseDouble);
CreateBenchmark('SparseElements', SparseElements);
CreateBenchmark('TypedUint8', TypedUint8);
CreateBenchmark('TypedInt32', TypedInt32);
CreateBenchmark('TypedFloat64', TypedFloat64);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = true;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,41 @@
// 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.
function benchy(fn, name) {
new BenchmarkSuite(name, [1], [
new Benchmark(name, true, false, 0, fn),
]);
}
function forLoop(array, searchValue) {
for (let i = 0; i < array.length; ++i) {
if (array[i] === searchValue) return true;
}
return farraylse;
}
function indexOf(array, searchValue) {
return array.indexOf(searchValue) !== -1;
}
function includes(array, searchValue) {
return array.includes(searchValue);
}
const PACKED = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
];
const HOLEY = new Array(PACKED.length);
for (let i = 0; i < PACKED.length; ++i)
HOLEY[i] = PACKED[i];
function helper(fn) {
const SEARCH_VALUE = 15;
const result = fn(PACKED, SEARCH_VALUE) && fn(HOLEY, SEARCH_VALUE);
return result;
}
benchy(() => helper(forLoop), 'for loop');
benchy(() => helper(indexOf), 'Array#indexOf');
benchy(() => helper(includes), 'Array#includes');

View File

@ -0,0 +1,23 @@
// 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.
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js')
function PrintResult(name, result) {
print(name + '-ArrayIndexOfIncludesPolymorphic(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 });

View File

@ -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
// ----------------------------------------------------------------------------
d8.file.execute('../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});

View File

@ -0,0 +1,155 @@
// 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.
var largeArray = Array.from(Array(1e5).keys());
// TODO(dhai): we should be able to use Array.prototype.map here, but that
// implementation is currently creating a HOLEY array.
for (var i = 0; i < 1e5; i++) {
largeArray[i] += 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
// ----------------------------------------------------------------------------
d8.file.execute('../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});

View File

@ -0,0 +1,162 @@
// 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(1e5);
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
// ----------------------------------------------------------------------------
d8.file.execute('../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 (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);
// The following benchmarks are so slow that they will time out.
// 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,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 largeArray = Array.from(Array(1e5).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
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadLargePacked(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);
// The following benchmarks are so slow that they will time out.
// 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,94 @@
// 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 iterating schemes against spread initial literals.
// Benchmarks for large smi maps.
var keys = Array.from(Array(1e4).keys());
var keyValuePairs = keys.map((value) => [value, value + 1]);
var map = new Map(keyValuePairs);
// ----------------------------------------------------------------------------
// Benchmark: SpreadKeys
// ----------------------------------------------------------------------------
function SpreadKeys() {
var newArr = [...map.keys()];
// basic sanity check
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadValues
// ----------------------------------------------------------------------------
function SpreadValues() {
var newArr = [...map.values()];
// basic sanity check
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfKeys
// ----------------------------------------------------------------------------
function ForOfKeys() {
var newArr = new Array(map.size);
var i = 0;
for (let x of map.keys()) {
newArr[i] = x;
i++;
}
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfValues
// ----------------------------------------------------------------------------
function ForOfValues() {
var newArr = new Array(map.size);
var i = 0;
for (let x of map.values()) {
newArr[i] = x;
i++;
}
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadLargeSmiMap(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('ForOfKeys', ForOfKeys);
CreateBenchmark('ForOfValues', ForOfValues);
CreateBenchmark('SpreadKeys', SpreadKeys);
CreateBenchmark('SpreadValues', SpreadValues);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = false;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,121 @@
// 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 iterating schemes against spread initial literals.
// Benchmarks for large smi sets.
var keys = Array.from(Array(1e4).keys());
var set = new Set(keys);
// ----------------------------------------------------------------------------
// Benchmark: Spread
// ----------------------------------------------------------------------------
function Spread() {
var newArr = [...set];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadKeys
// ----------------------------------------------------------------------------
function SpreadKeys() {
var newArr = [...set.keys()];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadValues
// ----------------------------------------------------------------------------
function SpreadValues() {
var newArr = [...set.values()];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOf
// ----------------------------------------------------------------------------
function ForOf() {
var newArr = new Array(set.size);
var i = 0;
for (let x of set) {
newArr[i] = x;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfKeys
// ----------------------------------------------------------------------------
function ForOfKeys() {
var newArr = new Array(set.size);
var i = 0;
for (let x of set.keys()) {
newArr[i] = x;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfValues
// ----------------------------------------------------------------------------
function ForOfValues() {
var newArr = new Array(set.size);
var i = 0;
for (let kv of set.values()) {
newArr[i] = kv;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadLargeSmiSet(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('ForOf', ForOf);
CreateBenchmark('ForOfKeys', ForOfKeys);
CreateBenchmark('ForOfValues', ForOfValues);
CreateBenchmark('Spread', Spread);
CreateBenchmark('SpreadKeys', SpreadKeys);
CreateBenchmark('SpreadValues', SpreadValues);
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 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
// ----------------------------------------------------------------------------
d8.file.execute('../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});

View File

@ -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 small packed double arrays.
var smallArray = Array.from(Array(100).keys());
for (var i = 0; i < 100; i++) {
smallArray[i] += 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
// ----------------------------------------------------------------------------
d8.file.execute('../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});

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
// ----------------------------------------------------------------------------
d8.file.execute('../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});

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
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadSmallPacked(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,93 @@
// 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 iterating schemes against spread initial literals.
// Benchmarks for small smi maps.
var keys = Array.from(Array(50).keys());
var keyValuePairs = keys.map((value) => [value, value + 1]);
var map = new Map(keyValuePairs);
// ----------------------------------------------------------------------------
// Benchmark: SpreadKeys
// ----------------------------------------------------------------------------
function SpreadKeys() {
var newArr = [...map.keys()];
// basic sanity check
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadValues
// ----------------------------------------------------------------------------
function SpreadValues() {
var newArr = [...map.values()];
// basic sanity check
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfKeys
// ----------------------------------------------------------------------------
function ForOfKeys() {
var newArr = new Array(map.size);
var i = 0;
for (let x of map.keys()) {
newArr[i] = x;
i++;
}
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfValues
// ----------------------------------------------------------------------------
function ForOfValues() {
var newArr = new Array(map.size);
var i = 0;
for (let x of map.values()) {
newArr[i] = x;
i++;
}
if (newArr.length != map.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadSmallSmiMap(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('ForOfKeys', ForOfKeys);
CreateBenchmark('ForOfValues', ForOfValues);
CreateBenchmark('SpreadKeys', SpreadKeys);
CreateBenchmark('SpreadValues', SpreadValues);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = false;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,120 @@
// 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 iterating schemes against spread initial literals.
// Benchmarks for small smi sets.
var keys = Array.from(Array(50).keys());
var set = new Set(keys);
// ----------------------------------------------------------------------------
// Benchmark: Spread
// ----------------------------------------------------------------------------
function Spread() {
var newArr = [...set];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadKeys
// ----------------------------------------------------------------------------
function SpreadKeys() {
var newArr = [...set.keys()];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: SpreadValues
// ----------------------------------------------------------------------------
function SpreadValues() {
var newArr = [...set.values()];
// basic sanity check
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOf
// ----------------------------------------------------------------------------
function ForOf() {
var newArr = new Array(set.size);
var i = 0;
for (let x of set) {
newArr[i] = x;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfKeys
// ----------------------------------------------------------------------------
function ForOfKeys() {
var newArr = new Array(set.size);
var i = 0;
for (let x of set.keys()) {
newArr[i] = x;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfValues
// ----------------------------------------------------------------------------
function ForOfValues() {
var newArr = new Array(set.size);
var i = 0;
for (let x of set.values()) {
newArr[i] = x;
i++;
}
if (newArr.length != set.size) throw 666;
return newArr;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralInitialSpreadSmallSmiSet(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('ForOf', ForOf);
CreateBenchmark('ForOfKeys', ForOfKeys);
CreateBenchmark('ForOfValues', ForOfValues);
CreateBenchmark('Spread', Spread);
CreateBenchmark('SpreadKeys', SpreadKeys);
CreateBenchmark('SpreadValues', SpreadValues);
BenchmarkSuite.config.doWarmup = true;
BenchmarkSuite.config.doDeterministic = false;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,97 @@
// 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 input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// ----------------------------------------------------------------------------
// Benchmark: Babel
// ----------------------------------------------------------------------------
function _toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
} else {
return Array.from(arr);
}
}
function Babel() {
const result = [0].concat(_toConsumableArray(input));
if (result.length != 11) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfPush
// ----------------------------------------------------------------------------
function ForOfPush() {
const result = [0];
for (const x of input) {
result.push(x);
}
if (result.length != 11) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: ForOfSet
// ----------------------------------------------------------------------------
function ForOfSet() {
const result = [0];
for (const x of input) {
result[result.length] = x;
}
if (result.length != 11) throw 666;
}
// ----------------------------------------------------------------------------
// Benchmark: Spread
// ----------------------------------------------------------------------------
function Spread() {
const result = [0, ...input];
if (result.length != 11) throw 666;
}
// ----------------------------------------------------------------------------
// Setup and Run
// ----------------------------------------------------------------------------
d8.file.execute('../base.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ArrayLiteralSpread(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
function CreateBenchmark(name, f) {
new BenchmarkSuite(name, [100], [ new Benchmark(name, false, false, 0, f) ]);
}
CreateBenchmark('Babel', Babel);
CreateBenchmark('ForOfPush', ForOfPush);
CreateBenchmark('ForOfSet', ForOfSet);
CreateBenchmark('Spread', Spread);
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({NotifyResult: PrintResult, NotifyError: PrintError});

View File

@ -0,0 +1,23 @@
// 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.
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js')
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 });

View File

@ -0,0 +1,141 @@
// 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 kArraySize = 4000;
let template_array = [];
for (let i = 0; i < kArraySize; ++i) {
template_array[i] = Math.floor(Math.random() * kArraySize);
}
let array_to_sort = [];
function AssertPackedSmiElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasSmiElements(array_to_sort),
"Element kind is not PACKED_SMI_ELEMENTS");
}
function AssertPackedDoubleElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasDoubleElements(array_to_sort),
"Element kind is not PACKED_DOUBLE_ELEMENTS");
}
function AssertPackedObjectElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasObjectElements(array_to_sort),
"Element kind is not PACKED_ELEMENTS");
}
function AssertHoleySmiElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasSmiElements(array_to_sort),
"Element kind is not HOLEY_SMI_ELEMENTS");
}
function AssertHoleyDoubleElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasDoubleElements(array_to_sort),
"Element kind is not HOLEY_DOUBLE_ELEMENTS");
}
function AssertHoleyObjectElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasObjectElements(array_to_sort),
"Element kind is not HOLEY_ELEMENTS");
}
function AssertDictionaryElements() {
assert(%HasDictionaryElements(array_to_sort),
"Element kind is not DICTIONARY_ELEMENTS");
}
function CreatePackedSmiArray() {
array_to_sort = Array.from(template_array);
AssertPackedSmiElements();
}
function CreatePackedDoubleArray() {
array_to_sort = Array.from(template_array, (x,_) => x + 0.1);
AssertPackedDoubleElements();
}
function CreatePackedObjectArray() {
array_to_sort = Array.from(template_array, (x,_) => `value ${x}`);
AssertPackedObjectElements();
}
function CreateHoleySmiArray() {
array_to_sort = Array.from(template_array);
delete array_to_sort[0];
AssertHoleySmiElements();
}
function CreateHoleyDoubleArray() {
array_to_sort = new Array(kArraySize);
for (let i = 0; i < kArraySize; ++i) {
array_to_sort[i] = template_array[i] + 0.1;
}
AssertHoleyDoubleElements();
}
function CreateHoleyObjectArray() {
array_to_sort = new Array(kArraySize);
for (let i = 0; i < kArraySize; ++i) {
array_to_sort[i] = `value ${template_array[i]}`;
}
AssertHoleyObjectElements();
}
function CreateDictionaryArray() {
array_to_sort = Array.from(template_array);
Object.defineProperty(array_to_sort, kArraySize - 2,
{ get: () => this.foo,
set: (v) => this.foo = v });
AssertDictionaryElements();
}
function Sort() {
array_to_sort.sort();
}
function CreateSortFn(comparefns = []) {
return () => {
for (let cmpfn of comparefns) {
array_to_sort.sort(cmpfn);
}
}
}
function cmp_smaller(a, b) {
if (a < b) return -1;
if (b < a) return 1;
return 0;
}
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);
}

View File

@ -0,0 +1,43 @@
// 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.
d8.file.execute('sort-base.js');
// Creates a comparison function, that will call the provided transform function
// after a set amount of comparisons. The transform function should cause the
// element kind of the array to change.
function CreateCompareFn(transformfn) {
return (a, b) => {
++counter;
if (counter == kArraySize/2) {
transformfn();
}
return cmp_smaller(a, b);
}
}
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);
createSortSuite(
'PackedSmiToPackedDouble', 1000, CreateSortFn([cmp_packed_smi_to_double]),
CreatePackedSmiArray, AssertPackedDoubleElements);
createSortSuite(
'HoleySmiToHoleyDouble', 1000, CreateSortFn([cmp_holey_smi_to_double]),
CreateHoleySmiArray, AssertHoleyDoubleElements);
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);
createSortSuite(
'PackedElementToDictionary', 1000, CreateSortFn([cmp_packed_to_dict]),
CreatePackedObjectArray, AssertDictionaryElements);
createSortSuite(
'HoleyElementToDictionary', 1000, CreateSortFn([cmp_holey_to_dict]),
CreateHoleyObjectArray, AssertDictionaryElements);

View File

@ -0,0 +1,20 @@
// 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.
d8.file.execute('sort-base.js');
// Each benchmark calls sort with multiple different comparison functions
// to create polyomorphic call sites. Most/all of the
// other sort benchmarks have monomorphic call sites.
let sortfn = CreateSortFn([cmp_smaller, cmp_greater]);
createSortSuite('PackedSmi', 1000, sortfn, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, sortfn, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, sortfn, CreatePackedObjectArray);
createSortSuite('HoleySmi', 1000, sortfn, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, sortfn, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, sortfn, CreateHoleyObjectArray);
createSortSuite('Dictionary', 1000, sortfn, CreateDictionaryArray);

View File

@ -0,0 +1,36 @@
// 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.
d8.file.execute('sort-base.js');
function SortAsc() {
array_to_sort.sort(cmp_smaller);
}
function Random(length) {
array_to_sort = [];
for (let i = 0; i < length; ++i) {
array_to_sort.push(Math.floor(Math.random() * length));
}
AssertPackedSmiElements();
}
function Sorted(length) {
array_to_sort = [];
for (let i = 0; i < length; ++i) {
array_to_sort.push(i);
}
AssertPackedSmiElements();
}
function CreateSortSuitesForLength(length) {
createSortSuite('Random' + length, 1000, SortAsc, () => Random(length));
createSortSuite('Sorted' + length, 1000, SortAsc, () => Sorted(length));
}
CreateSortSuitesForLength(10);
CreateSortSuitesForLength(100);
CreateSortSuitesForLength(1000);
CreateSortSuitesForLength(10000);
CreateSortSuitesForLength(100000);

View File

@ -0,0 +1,20 @@
// 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.
d8.file.execute('sort-base.js');
function SetupMegamorphic() {
CreatePackedSmiArray();
Array.prototype.sort.call([1.1]);
Array.prototype.sort.call(['a']);
Array.prototype.sort.call([2,,3]);
Array.prototype.sort.call([0.2,,0.1]);
Array.prototype.sort.call(['b',,'a']);
Array.prototype.sort.call({});
}
createSortSuite('Base', 1000, Sort, SetupMegamorphic);
createSortSuite('MultipleCompareFns', 1000,
CreateSortFn([cmp_smaller, cmp_greater]), SetupMegamorphic);

View File

@ -0,0 +1,108 @@
// 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.
d8.file.execute('sort-base.js');
const kLength = 2e4;
const kLengthHalf = kLength >>> 1;
function SortAsc() {
array_to_sort.sort(cmp_smaller);
}
function Up(a, length) {
for (let i = 0; i < length; ++i) {
a.push(i);
}
}
function Down(a, length) {
for (let i = 0; i < length; ++i) {
a.push(length - i);
}
}
function SawSeq(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(i);
if (++count >= length) return;
}
}
}
function SawSeq2(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(i);
if (++count >= length) return;
}
for (let i = 0; i < tooth; ++i) {
a.push(tooth - i);
if (++count >= length) return;
}
}
}
function SawSeq3(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(tooth - i);
if (++count >= length) return;
}
}
}
function Random(a, length) {
for (let i = 0; i < length; ++i) {
a.push(Math.floor(Math.random() * length));
}
}
function TearDown() {
// Sanity check that the array is sorted.
let length = array_to_sort.length - 1;
for (let i = 0; i < length; ++i) {
if (array_to_sort[i] > array_to_sort[i + 1]) {
throw "Not sorted correctly: i = " + i;
}
}
array_to_sort = [];
}
let SetupSaw1000 = () => SawSeq(array_to_sort, 1000, kLength);
let SetupSaw500 = () => SawSeq(array_to_sort, 500, kLength);
let SetupSaw200 = () => SawSeq(array_to_sort, 200, kLength);
let SetupSaw200Sym = () => SawSeq2(array_to_sort, 200, kLength);
let SetupSaw200Down = () => SawSeq3(array_to_sort, 200, kLength);
function SetupPreSortedHalfs(firstfn, secondfn) {
array_to_sort = [];
firstfn(array_to_sort, kLengthHalf);
secondfn(array_to_sort, kLengthHalf);
}
let SetupUpDown = () => SetupPreSortedHalfs(Up, Down);
let SetupUpUp = () => SetupPreSortedHalfs(Up, Up);
let SetupDownDown = () => SetupPreSortedHalfs(Down, Down);
let SetupDownUp = () => SetupPreSortedHalfs(Down, Up);
createSortSuite(
'Random', 1000, SortAsc, () => Random(array_to_sort, kLength), 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);

View File

@ -0,0 +1,15 @@
// 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.
d8.file.execute('sort-base.js');
createSortSuite('PackedSmi', 1000, Sort, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, Sort, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, Sort, CreatePackedObjectArray);
createSortSuite('HoleySmi', 1000, Sort, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, Sort, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, Sort, CreateHoleyObjectArray);
createSortSuite('Dictionary', 1000, Sort, CreateDictionaryArray);

View File

@ -0,0 +1,169 @@
// Copyright 2016 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.
new BenchmarkSuite('BaselineES2017', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
function _asyncToGenerator(fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
return Promise.resolve(value)
.then(function (value) {
step("next", value);
}, function (err) {
step("throw", err);
});
}
}
return step("next");
});
};
}
var a, b, c, d, e, f, g, h, i, j, x;
function Setup() {
x = Promise.resolve();
j = (() => {
var _ref = _asyncToGenerator(function* () {
return x;
});
function j() {
return _ref.apply(this, arguments);
}
return j;
})();
i = (() => {
var _ref2 = _asyncToGenerator(function* () {
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
return j();
});
function i() {
return _ref2.apply(this, arguments);
}
return i;
})();
h = (() => {
var _ref3 = _asyncToGenerator(function* () {
return i();
});
function h() {
return _ref3.apply(this, arguments);
}
return h;
})();
g = (() => {
var _ref4 = _asyncToGenerator(function* () {
return h();
});
function g() {
return _ref4.apply(this, arguments);
}
return g;
})();
f = (() => {
var _ref5 = _asyncToGenerator(function* () {
return g();
});
function f() {
return _ref5.apply(this, arguments);
}
return f;
})();
e = (() => {
var _ref6 = _asyncToGenerator(function* () {
return f();
});
function e() {
return _ref6.apply(this, arguments);
}
return e;
})();
d = (() => {
var _ref7 = _asyncToGenerator(function* () {
return e();
});
function d() {
return _ref7.apply(this, arguments);
}
return d;
})();
c = (() => {
var _ref8 = _asyncToGenerator(function* () {
return d();
});
function c() {
return _ref8.apply(this, arguments);
}
return c;
})();
b = (() => {
var _ref9 = _asyncToGenerator(function* () {
return c();
});
function b() {
return _ref9.apply(this, arguments);
}
return b;
})();
a = (() => {
var _ref10 = _asyncToGenerator(function* () {
return b();
});
function a() {
return _ref10.apply(this, arguments);
}
return a;
})();
%PerformMicrotaskCheckpoint();
}
function Basic() {
a();
%PerformMicrotaskCheckpoint();
}

View File

@ -0,0 +1,51 @@
// Copyright 2016 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.
new BenchmarkSuite('BaselineNaivePromises', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
var a,b,c,d,e,f,g,h,i,j,x;
function Setup() {
x = Promise.resolve();
j = function j(p) { return p; };
i = function i(p) {
return p.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j);
};
h = function h(p) { return p; };
g = function g(p) { return p; };
f = function f(p) { return p; };
e = function e(p) { return p; };
d = function d(p) { return p; };
c = function c(p) { return p; };
b = function b(p) { return p; };
a = function a(p) { return p; };
%PerformMicrotaskCheckpoint();
}
function Basic() {
x.then(j)
.then(i)
.then(h)
.then(g)
.then(f)
.then(e)
.then(d)
.then(c)
.then(b)
.then(a);
%PerformMicrotaskCheckpoint();
}

View File

@ -0,0 +1,43 @@
// Copyright 2016 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.
new BenchmarkSuite('Native', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
var a,b,c,d,e,f,g,h,i,j,x;
function Setup() {
x = Promise.resolve();
j = async function j() { return x; };
i = async function i() {
await j();
await j();
await j();
await j();
await j();
await j();
await j();
await j();
await j();
return j();
};
h = async function h() { return i(); };
g = async function g() { return h(); };
f = async function f() { return g(); };
e = async function e() { return f(); };
d = async function d() { return e(); };
c = async function c() { return d(); };
b = async function b() { return c(); };
a = async function a() { return b(); };
%PerformMicrotaskCheckpoint();
}
function Basic() {
a();
%PerformMicrotaskCheckpoint();
}

View File

@ -0,0 +1,28 @@
// Copyright 2016 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.
d8.file.execute('../base.js');
d8.file.execute('baseline-babel-es2017.js');
d8.file.execute('baseline-naive-promises.js');
d8.file.execute('native.js');
var success = true;
function PrintResult(name, result) {
print(name + '-AsyncAwait(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

123
deps/v8/test/js-perf-test/BigInt/add.js vendored Normal file
View File

@ -0,0 +1,123 @@
// Copyright 2019 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.
"use strict";
d8.file.execute('bigint-util.js');
let initial_sum = 0n;
let a = 0n;
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Add-Zero', [1000], [
new Benchmark('Add-Zero', true, false, 0, TestAddZero, SetUpTestAddZero)
]);
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Add-SameSign-${d}`, [1000], [
new Benchmark(`Add-SameSign-${d}`, true, false, 0, TestAddSameSign,
() => SetUpTestAddSameSign(d))
]);
});
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Add-DifferentSign-${d}`, [1000], [
new Benchmark(`Add-DifferentSign-${d}`, true, false, 0,
TestAddDifferentSign, () => SetUpTestAddDifferentSign(d))
]);
});
new BenchmarkSuite('Add-Random', [1000], [
new Benchmark('Add-Random', true, false, 0, TestAddRandom,
SetUpTestAddRandom)
]);
function SetUpTestAddZero() {
initial_sum = 42n;
}
function TestAddZero() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = 0n + sum;
}
return sum;
}
function SetUpTestAddSameSign(bits) {
// Add two small random positive values to make sure the sum does not grow
// in digits.
initial_sum = SmallRandomBigIntWithBits(bits);
a = SmallRandomBigIntWithBits(bits);
}
function TestAddSameSign() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = a + sum;
}
return sum;
}
function SetUpTestAddDifferentSign(bits) {
// Add a small random negative value to a large positive one to make sure the
// sum does not shrink in digits.
initial_sum = MaxBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestAddDifferentSign() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = a + sum;
}
return sum;
}
function SetUpTestAddRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestAddRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = random_bigints[i] + sum;
}
return sum;
}

View File

@ -0,0 +1,88 @@
// Copyright 2021 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.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt64-${d}`, [1000], [
new Benchmark(`AsInt64-${d}`, true, false, 0, TestAsInt64,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt32-${d}`, [1000], [
new Benchmark(`AsInt32-${d}`, true, false, 0, TestAsInt32,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt8-${d}`, [1000], [
new Benchmark(`AsInt8-${d}`, true, false, 0, TestAsInt8,
() => SetUpTestAsIntN(d))
]);
});
function SetUpTestAsIntN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsInt64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsInt32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsInt8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(8, random_bigints[i % 8]);
}
return result;
}

View File

@ -0,0 +1,88 @@
// Copyright 2019 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.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint64-${d}`, [1000], [
new Benchmark(`AsUint64-${d}`, true, false, 0, TestAsUint64,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint32-${d}`, [1000], [
new Benchmark(`AsUint32-${d}`, true, false, 0, TestAsUint32,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint8-${d}`, [1000], [
new Benchmark(`AsUint8-${d}`, true, false, 0, TestAsUint8,
() => SetUpTestAsUintN(d))
]);
});
function SetUpTestAsUintN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsUint64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsUint32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsUint8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(8, random_bigints[i % 8]);
}
return result;
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 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.
"use strict";
// Test configuration.
const TEST_ITERATIONS = 1000;
const SLOW_TEST_ITERATIONS = 50;
const BITS_CASES = [32, 64, 1024, 8192];
const RANDOM_BIGINTS_MAX_BITS = 64 * 100;
const BIGINT_MAX_BITS = %BigIntMaxLengthBits();
function RandomHexDigit(allow_zero) {
const chars = allow_zero ? '0123456789ABCDEF' : '123456789ABCDEF';
return chars.charAt(Math.floor(Math.random() * chars.length));
}
// Some benchmarks shall compute sums but the result must not grow in terms
// of digits. These can use "small" BigInts, which are BigInts where the most
// significant bits of a digit are 0, so it does not overflow.
function SmallRandomBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
// Make sure it does not start with four 0-bits.
let s = "0x" + RandomHexDigit(false);
bits -= 4;
// Digits are at least 32 bits long, so we round down to the next smaller
// multiple of 32 to keep the most significant digit small.
bits = Math.floor(bits / 32) * 32;
for (; bits > 0; bits -= 4) {
s += RandomHexDigit(true);
}
return BigInt(s);
}
function MaxBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
let s = "0x";
s += "F".repeat(bits / 4);
return BigInt(s);
}
// Generates a random BigInt between 2^(bits-4) and 2^bits-1 (for bits > 0).
function RandomBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
// Make sure it does not start with four 0-bits.
let s = "0x" + RandomHexDigit(false);
bits -= 4;
// Randomly generate remaining bits.
for (; bits > 0; bits -= 4) {
s += RandomHexDigit(true);
}
return BigInt(s);
}

View File

@ -0,0 +1,95 @@
// Copyright 2022 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.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('BitwiseAnd-Zero', [1000], [
new Benchmark('BitwiseAnd-Zero', true, false, 0, TestBitwiseAndZero)
]);
new BenchmarkSuite('BitwiseAnd-Small', [1000], [
new Benchmark('BitwiseAnd-Small', true, false, 0, TestBitwiseAnd,
SetUpTestBitwiseAndSmall)
]);
new BenchmarkSuite('BitwiseAnd-Small-Truncated', [1000], [
new Benchmark('BitwiseAnd-Small-Truncated', true, false, 0,
TestBitwiseAndTruncated, SetUpTestBitwiseAndSmall)
]);
new BenchmarkSuite('BitwiseAnd-Random', [1000], [
new Benchmark('BitwiseAnd-Random', true, false, 0, TestBitwiseAnd,
SetUpTestBitwiseAndRandom)
]);
function TestBitwiseAndZero() {
let result = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
result += 0n & i;
}
return result;
}
function SetUpTestBitwiseAndSmall() {
random_bigints = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(60);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function SetUpTestBitwiseAndRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestBitwiseAnd() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
result += random_bigints[i] & random_bigints[i + 1];
}
return result;
}
function TestBitwiseAndTruncated() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
// Truncated explicitly
result += BigInt.asIntN(64, random_bigints[i] & random_bigints[i + 1]);
}
return result;
}

View File

@ -0,0 +1,120 @@
// Copyright 2022 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.
"use strict";
d8.file.execute('bigint-util.js');
let random_dividends = [];
let random_divisors = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Divide-One', [1000], [
new Benchmark('Divide-One', true, false, 0, TestDivideOne)
]);
new BenchmarkSuite('Divide-Small', [1000], [
new Benchmark('Divide-Small', true, false, 0, TestDivideSmall,
SetUpTestDivideSmall)
]);
new BenchmarkSuite('Divide-Small-Truncated', [1000], [
new Benchmark('Divide-Small-Truncated', true, false, 0,
TestDivideSmallTruncated, SetUpTestDivideSmall)
]);
new BenchmarkSuite('Divide-Random', [10000], [
new Benchmark('Divide-Random', true, false, 0, TestDivideRandom,
SetUpTestDivideRandom)
]);
function TestDivideOne() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += i / 1n;
}
return sum;
}
function SetUpTestDivideSmall() {
random_dividends = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(60);
random_dividends.push(Math.random() < 0.5 ? -bigint : bigint);
}
random_divisors = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(32);
random_divisors.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestDivideSmall() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += random_dividends[i] / random_divisors[i];
}
return sum;
}
function TestDivideSmallTruncated() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += BigInt.asIntN(64, random_dividends[i] / random_divisors[i]);
}
return sum;
}
function SetUpTestDivideRandom() {
random_dividends = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_dividends.push(Math.random() < 0.5 ? -bigint : bigint);
}
random_divisors = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
// Avoid divide-by-zero
const bits = Math.floor(1 + Math.random() * (max_in_4bits - 1)) * 4;
const bigint = RandomBigIntWithBits(bits);
random_divisors.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestDivideRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += random_dividends[i] / random_divisors[i];
}
return sum;
}

View File

@ -0,0 +1,95 @@
// Copyright 2022 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.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Multiply-Zero', [1000], [
new Benchmark('Multiply-Zero', true, false, 0, TestMultiplyZero)
]);
new BenchmarkSuite('Multiply-Small', [1000], [
new Benchmark('Multiply-Small', true, false, 0, TestMultiplySmall)
]);
new BenchmarkSuite('Multiply-Small-Truncated', [1000], [
new Benchmark('Multiply-Small-Truncated', true, false, 0,
TestMultiplySmallTruncated)
]);
new BenchmarkSuite('Multiply-Random', [10000], [
new Benchmark('Multiply-Random', true, false, 0, TestMultiplyRandom,
SetUpTestMultiplyRandom)
]);
function TestMultiplyZero() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += 0n * i;
}
return sum;
}
function TestMultiplySmall() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += i * (i + 1n);
}
return sum;
}
function TestMultiplySmallTruncated() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += BigInt.asIntN(64, i * (i + 1n));
}
return sum;
}
function SetUpTestMultiplyRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestMultiplyRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
sum += random_bigints[i] * random_bigints[i + 1];
}
return sum;
}

28
deps/v8/test/js-perf-test/BigInt/run.js vendored Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2019 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.
"use strict";
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js');
var success = true;
function PrintResult(name, result) {
print(`BigInt-${name}(Score): ${result}`);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,219 @@
// Copyright 2021 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.
"use strict";
d8.file.execute('bigint-util.js');
let a = 0n;
let random_bigints = [];
let small_shift_values = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [100], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('ShiftLeft-Small', [1000], [
new Benchmark('ShiftLeft-Small', true, false, 0,
TestShiftLeftSmall, SetUpTestShiftLeftSmall)
]);
new BenchmarkSuite('ShiftLeft-Random', [1000], [
new Benchmark('ShiftLeft-Random', true, false, 0,
TestShiftLeftRandom, SetUpTestShiftLeftRandom)
]);
new BenchmarkSuite('ShiftLeft-Growing', [1000], [
new Benchmark('ShiftLeft-Growing', true, false, 0,
TestShiftLeftGrowing, SetUpTestShiftLeftGrowing)
]);
new BenchmarkSuite('ShiftRight-Maximum', [1000], [
new Benchmark('ShiftRight-Maximum', true, false, 0,
TestShiftRightMaximum, SetUpTestShiftRightMaximum)
]);
new BenchmarkSuite('ShiftRight-ToZero', [1000], [
new Benchmark('ShiftRight-ToZero', true, false, 0,
TestShiftRightToZero, SetUpTestShiftRightToZero)
]);
new BenchmarkSuite('ShiftRight-Small', [1000], [
new Benchmark('ShiftRight-Small', true, false, 0,
TestShiftRightSmall, SetUpTestShiftRightSmall)
]);
new BenchmarkSuite('ShiftRight-Random', [1000], [
new Benchmark('ShiftRight-Random', true, false, 0,
TestShiftRightRandom, SetUpTestShiftRightRandom)
]);
new BenchmarkSuite('ShiftRight-Shrinking', [1000], [
new Benchmark('ShiftRight-Shrinking', true, false, 0,
TestShiftRightShrinking, SetUpTestShiftRightShrinking)
]);
function SetUpRandomBigInts() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < Math.max(TEST_ITERATIONS, SLOW_TEST_ITERATIONS); ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function SetUpTestShiftLeftSmall() {
random_bigints = [];
// Set up all values such that the left shifted values still fit into one
// digit.
for (let i = 0; i < TEST_ITERATIONS; ++i) {
random_bigints[i] = SmallRandomBigIntWithBits(16);
small_shift_values[i] = SmallRandomBigIntWithBits(4);
}
}
function TestShiftLeftSmall() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] << small_shift_values[i];
}
return result;
}
function SetUpTestShiftLeftRandom() {
if (RANDOM_BIGINTS_MAX_BITS + 2**16 > BIGINT_MAX_BITS) {
throw "Invalid Test Configuration";
}
small_shift_values = [];
SetUpRandomBigInts();
for (let i = 0; i < TEST_ITERATIONS; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(16);
}
}
function TestShiftLeftRandom() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] << small_shift_values[i];
}
return result;
}
function SetUpTestShiftLeftGrowing() {
if (2**4 + (1000 * (2**8)) > BIGINT_MAX_BITS) {
throw "Invalid Test Configuration";
}
small_shift_values = [];
for (let i = 0; i < 1000; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(8);
}
}
function TestShiftLeftGrowing() {
let result = a;
for (let i = 0; i < 1000; ++i) {
result = result << small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightMaximum() {
// Right shifting by 2^80 will shift out all bits.
a = SmallRandomBigIntWithBits(80);
SetUpRandomBigInts();
}
function TestShiftRightMaximum() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> a;
}
return result;
}
function SetUpTestShiftRightToZero() {
// Choose a such that every random BigInt >> a will result in 0n/-1n.
a = BigInt(2 * RANDOM_BIGINTS_MAX_BITS);
SetUpRandomBigInts();
}
function TestShiftRightToZero() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> a;
}
return result;
}
function SetUpTestShiftRightSmall() {
random_bigints = [];
// We construct small BigInts with 32 bits such that they have a single digit
// even on 32bit architectures.
for (let i = 0; i < TEST_ITERATIONS; ++i) {
random_bigints[i] = SmallRandomBigIntWithBits(32);
small_shift_values[i] = BigInt(Math.floor(Math.random() * 30) + 1);
}
}
function TestShiftRightSmall() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightRandom() {
random_bigints = [];
small_shift_values = [];
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits_in_4 = Math.floor(Math.random() * max_in_4bits);
const shift_in_4 = Math.floor(Math.random() * bits_in_4);
const bigint = RandomBigIntWithBits(bits_in_4 * 4);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
small_shift_values.push(BigInt(shift_in_4 * 4));
}
}
function TestShiftRightRandom() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightShrinking() {
small_shift_values = [];
// Choose values such that shifting right by 1000 times will not make the
// result to go 0n/-1n.
a = RandomBigIntWithBits(16*1000);
for (let i = 0; i < 1000; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(4);
}
}
function TestShiftRightShrinking() {
let result = a;
for (let i = 0; i < 1000; ++i) {
result = result >> small_shift_values[i];
}
return result;
}

View File

@ -0,0 +1,124 @@
// Copyright 2019 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.
"use strict";
d8.file.execute('bigint-util.js');
let initial_diff = 0n;
let a = 0n;
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Subtract-Zero', [1000], [
new Benchmark('Subtract-Zero', true, false, 0, TestSubtractZero,
SetUpTestSubtractZero)
]);
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Subtract-SameSign-${d}`, [1000], [
new Benchmark(`Subtract-SameSign-${d}`, true, false, 0,
TestSubtractSameSign, () => SetUpTestSubtractSameSign(d))
]);
});
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Subtract-DifferentSign-${d}`, [1000], [
new Benchmark(`Subtract-DifferentSign-${d}`, true, false, 0,
TestSubtractDifferentSign, () => SetUpTestSubtractDifferentSign(d))
]);
});
new BenchmarkSuite('Subtract-Random', [1000], [
new Benchmark('Subtract-Random', true, false, 0, TestSubtractRandom,
SetUpTestSubtractRandom)
]);
function SetUpTestSubtractSameSign(bits) {
// Subtract a small random negative value from the maximal negative number to
// make sure the result stays negative.
initial_diff = -MaxBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestSubtractSameSign() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - a;
}
return diff;
}
function SetUpTestSubtractDifferentSign(bits) {
// Subtract a small random negative value from a small positive value so that
// the differnce stays positive but does not grow in digits.
initial_diff = SmallRandomBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestSubtractDifferentSign() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - a;
}
return diff;
}
function SetUpTestSubtractRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestSubtractRandom() {
let diff = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - random_bigints[i];
}
return diff;
}
function SetUpTestSubtractZero() {
initial_diff = 42n;
}
function TestSubtractZero() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - 0n;
}
return diff;
}

View File

@ -0,0 +1,62 @@
// Copyright 2019 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.
"use strict";
const ITERATIONS = 100000;
// This dummy ensures that the feedback for benchmark.run() in the Measure function
// from base.js is not monomorphic, thereby preventing the benchmarks below from being inlined.
// This ensures consistent behavior and comparable results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('ToBoolean', [10000], [
new Benchmark('ToBoolean', true, false, 0, TestToBoolean),
]);
new BenchmarkSuite('BooleanConstructor', [10000], [
new Benchmark('BooleanConstructor', true, false, 0, TestBooleanConstructor),
]);
new BenchmarkSuite('NewBooleanConstructor', [10000], [
new Benchmark('NewBooleanConstructor', true, false, 0, TestNewBooleanConstructor),
]);
function TestBooleanConstructor() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = Boolean(i % 2 == 0 ? 42n : 32n);
}
return kl;
}
function TestNewBooleanConstructor() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = new Boolean(i % 2 == 0 ? 42n : 32n);
}
return kl;
}
function TestToBoolean() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = (i % 2 == 0 ? 42n : 32n) ? true : false;
}
return kl;
}

View File

@ -0,0 +1,40 @@
// Copyright 2019 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
function objectLookupStringConstant() {
const x = { 1: "foo" };
for (var i = 0; i < 1000; ++i) {
const p = x["1"];
}
}
function objectLookupIndexNumber() {
const x = { 1: "foo" };
const a = 1;
for (var i = 0; i < 1000; ++i) {
const p = x[a];
}
}
function objectLookupIndexString() {
const x = { 1: "foo" };
const a = "1";
for (var i = 0; i < 1000; ++i) {
const p = x[a];
}
}
addBenchmark('Object-Lookup-String-Constant', objectLookupStringConstant);
addBenchmark('Object-Lookup-Index-Number', objectLookupIndexNumber);
addBenchmark('Object-Lookup-Index-String', objectLookupIndexString);

View File

@ -0,0 +1,60 @@
// Copyright 2019 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('Smi-Value', smiValue);
addBenchmark('Prototype-Chain-Value', functionOnPrototypeValue);
// TODO(all): might be a good idea to also do with receivers: double, HeapObject
// with map, HeapObject, tagged, empty getter / accessor.
// Also, element keyed loads (in another file, probably?) both with strings and
// numbers for normal, cons,and sliced strings (for named properties).
// Also, monomorphic vs poly vs mega.
function smiValue() {
function constructSmi() {
this.smi = 0;
}
let o = new constructSmi();
for (var i = 0; i < 1000; ++i) {
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi; o.smi;
}
}
function functionOnPrototypeValue() {
function objectWithPrototypeChain() {
}
objectWithPrototypeChain.prototype.__proto__ =
{__proto__:{__proto__:{__proto__:{f(){}}}}};
let o = new objectWithPrototypeChain();
for (var i = 0; i < 1000; ++i) {
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f; o.f;
}
}

View File

@ -0,0 +1,60 @@
// Copyright 2019 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('LoadGlobal', ldaGlobal);
addBenchmark('LoadGlobalInsideTypeof', ldaGlobalInsideTypeof);
var g_var = 10;
function ldaGlobal() {
for (var i = 0; i < 1000; ++i) {
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var; g_var;
}
}
function ldaGlobalInsideTypeof() {
for (var i = 0; i < 1000; ++i) {
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
typeof(g_var); typeof(g_var); typeof(g_var); typeof(g_var);
}
}

View File

@ -0,0 +1,336 @@
// Copyright 2017 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('Smi-Add', addSmi);
addBenchmark('Number-Add', addNumber);
addBenchmark('Number-Oddball-Add', addOddball);
addBenchmark('String-Add', addString);
addBenchmark('Number-String-Add', addNumberString);
addBenchmark('Object-Add', addObject);
addBenchmark('Smi-Sub', subSmi);
addBenchmark('Number-Sub', subNumber);
addBenchmark('Number-Oddball-Sub', subOddball);
addBenchmark('Object-Sub', subObject);
addBenchmark('Smi-Mul', mulSmi);
addBenchmark('Number-Mul', mulNumber);
addBenchmark('Number-Oddball-Mul', mulOddball);
addBenchmark('Object-Mul', mulObject);
addBenchmark('Smi-Div', divSmi);
addBenchmark('Number-Div', divNumber);
addBenchmark('Number-Oddball-Div', divOddball);
addBenchmark('Object-Div', divObject);
addBenchmark('Smi-Mod', modSmi);
addBenchmark('Number-Mod', modNumber);
addBenchmark('Number-Oddball-Mod', modOddball);
addBenchmark('Object-Mod', modObject);
addBenchmark('Smi-Constant-Add', addSmiConstant);
addBenchmark('Smi-Constant-Sub', subSmiConstant);
addBenchmark('Smi-Constant-Mul', mulSmiConstant);
addBenchmark('Smi-Constant-Div', divSmiConstant);
addBenchmark('Smi-Constant-Mod', modSmiConstant);
addBenchmark('Smi-Increment', SmiIncrement);
addBenchmark('Number-Increment', NumberIncrement);
addBenchmark('Smi-Decrement', SmiDecrement);
addBenchmark('Number-Decrement', NumberDecrement);
function add(a, b) {
for (var i = 0; i < 1000; ++i) {
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b; a + b;
}
}
function sub(a, b) {
for (var i = 0; i < 1000; ++i) {
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b; a - b;
}
}
function mul(a, b) {
for (var i = 0; i < 1000; ++i) {
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b; a * b;
}
}
function div(a, b) {
for (var i = 0; i < 1000; ++i) {
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b; a / b;
}
}
function mod(a, b) {
for (var i = 0; i < 1000; ++i) {
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b; a % b;
}
}
function addSmiConstant(a) {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10; a + 10;
}
}
function subSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10; a - 10;
}
}
function mulSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10; a * 10;
}
}
function divSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10; a / 10;
}
}
function modSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10; a % 10;
}
}
function inc(a) {
for (var i = 0; i < 1000; ++i) {
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a; ++a;
// To ensure it is always in SmiRange for Smi operation.
a -= 1000;
}
}
function dec(a) {
for (var i = 0; i < 1000; ++i) {
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
--a; --a; --a; --a; --a; --a; --a; --a; --a; --a;
// To ensure it is always in SmiRange for Smi operation.
a += 1000;
}
}
function addSmi() {
add(10, 20);
}
function addNumber() {
add(0.333, 0.5);
}
function addOddball() {
add(0.333, true);
}
function addString() {
add("abc", "def");
}
function addNumberString() {
add("abc", 1.23);
}
function addObject() {
add({x: 1, y:2}, {x:3, y:4});
}
function subSmi() {
sub(10, 20);
}
function subNumber() {
sub(0.333, 0.5);
}
function subOddball() {
sub(0.333, true);
}
function subObject() {
sub({x: 1, y:2}, {x:3, y:4});
}
function mulSmi() {
mul(10, 20);
}
function mulNumber() {
mul(0.333, 0.5);
}
function mulOddball() {
mul(0.333, true);
}
function mulObject() {
mul({x: 1, y:2}, {x:3, y:4});
}
function divSmi() {
div(10, 20);
}
function divNumber() {
div(0.333, 0.5);
}
function divOddball() {
div(0.333, true);
}
function divObject() {
div({x: 1, y:2}, {x:3, y:4});
}
function modSmi() {
mod(10, 20);
}
function modNumber() {
mod(0.333, 0.5);
}
function modOddball() {
mod(0.333, true);
}
function modObject() {
mod({x: 1, y:2}, {x:3, y:4});
}
function SmiIncrement() {
inc(3);
}
function NumberIncrement() {
inc(0.33);
}
function SmiDecrement() {
dec(3);
}
function NumberDecrement() {
dec(0.33);
}

View File

@ -0,0 +1,264 @@
// Copyright 2017 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('Smi-Or', orSmi);
addBenchmark('Number-Or', orNumber);
addBenchmark('Smi-Xor', xorSmi);
addBenchmark('Number-Xor', xorNumber);
addBenchmark('Smi-And', andSmi);
addBenchmark('Number-And', andNumber);
addBenchmark('Smi-Constant-Or', orSmiConstant);
addBenchmark('Smi-Constant-Xor', xorSmiConstant);
addBenchmark('Smi-Constant-And', andSmiConstant);
addBenchmark('Smi-ShiftLeft', shiftLeftSmi);
addBenchmark('Number-ShiftLeft', shiftLeftNumber);
addBenchmark('Smi-ShiftRight', shiftRightSmi);
addBenchmark('Number-ShiftRight', shiftRightNumber);
addBenchmark('Smi-ShiftRightLogical', shiftRightLogicalSmi);
addBenchmark('Number-ShiftRightLogical', shiftRightLogicalNumber);
addBenchmark('Smi-Constant-ShiftLeft', shiftLeftSmiConstant);
addBenchmark('Smi-Constant-ShiftRight', shiftRightSmiConstant);
addBenchmark('Smi-Constant-ShiftRightLogical', shiftRightLogicalSmiConstant);
function bitwiseOr(a, b) {
for (var i = 0; i < 1000; ++i) {
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b; a | b;
}
}
function bitwiseXor(a, b) {
for (var i = 0; i < 1000; ++i) {
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b; a ^ b;
}
}
function bitwiseAnd(a, b) {
for (var i = 0; i < 1000; ++i) {
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b; a & b;
}
}
function shiftLeft(a, b) {
for (var i = 0; i < 1000; ++i) {
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b; a << b;
}
}
function shiftRight(a, b) {
for (var i = 0; i < 1000; ++i) {
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b; a >> b;
}
}
function shiftRightLogical(a, b) {
for (var i = 0; i < 1000; ++i) {
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b; a >>> b;
}
}
function orSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10; a | 10;
}
}
function xorSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10; a ^ 10;
}
}
function andSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10; a & 10;
}
}
function shiftLeftSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10; a << 10;
}
}
function shiftRightSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10; a >> 10;
}
}
function shiftRightLogicalSmiConstant() {
var a = 20;
for (var i = 0; i < 1000; ++i) {
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10; a >>> 10;
}
}
function orSmi() {
bitwiseOr(10, 20);
}
function orNumber() {
bitwiseOr(0.33, 0.5);
}
function xorSmi() {
bitwiseXor(10, 20);
}
function xorNumber() {
bitwiseXor(0.33, 0.5);
}
function andSmi() {
bitwiseAnd(10, 20);
}
function andNumber() {
bitwiseAnd(0.33, 0.5);
}
function shiftLeftSmi() {
shiftLeft(10, 20);
}
function shiftLeftNumber() {
shiftLeft(0.333, 0.5);
}
function shiftRightSmi() {
shiftRight(10, 20);
}
function shiftRightNumber() {
shiftRight(0.333, 0.5);
}
function shiftRightLogicalSmi() {
shiftRightLogical(10, 20);
}
function shiftRightLogicalNumber() {
shiftRightLogical(0.333, 0.5);
}

View File

@ -0,0 +1,271 @@
// Copyright 2017 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('Smi-StrictEquals-True', SmiStrictEqualsTrue);
addBenchmark('Smi-StrictEquals-False', SmiStrictEqualsFalse);
addBenchmark('Number-StrictEquals-True', NumberStrictEqualsTrue);
addBenchmark('Number-StrictEquals-False', NumberStrictEqualsFalse);
addBenchmark('String-StrictEquals-True', StringStrictEqualsTrue);
addBenchmark('String-StrictEquals-False', StringStrictEqualsFalse);
addBenchmark('SmiString-StrictEquals', MixedStrictEquals);
addBenchmark('Boolean-StrictEquals', BooleanStrictEquals);
addBenchmark('Smi-Equals-True', SmiEqualsTrue);
addBenchmark('Smi-Equals-False', SmiEqualsFalse);
addBenchmark('Number-Equals-True', NumberEqualsTrue);
addBenchmark('Number-Equals-False', NumberEqualsFalse);
addBenchmark('String-Equals-True', StringEqualsTrue);
addBenchmark('String-Equals-False', StringEqualsFalse);
addBenchmark('SmiString-Equals', MixedEquals);
addBenchmark('ObjectNull-Equals', ObjectEqualsNull);
addBenchmark('Smi-RelationalCompare', SmiRelationalCompare);
addBenchmark('Number-RelationalCompare', NumberRelationalCompare);
addBenchmark('String-RelationalCompare', StringRelationalCompare);
addBenchmark('SmiString-RelationalCompare', MixedRelationalCompare);
var null_object;
function strictEquals(a, b) {
for (var i = 0; i < 1000; ++i) {
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
}
}
function strictEqualsBoolean(a) {
var ret;
for (var i = 0; i < 1000; ++i) {
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
}
return ret;
}
function equals(a, b) {
for (var i = 0; i < 1000; ++i) {
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
}
}
// Relational comparison handlers are similar, so use one benchmark to measure
// all of them.
function relationalCompare(a, b) {
for (var i = 0; i < 1000; ++i) {
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
}
}
function SmiStrictEqualsFalse() {
strictEquals(10, 20);
}
function SmiStrictEqualsTrue() {
strictEquals(10, 10);
}
function NumberStrictEqualsFalse() {
strictEquals(0.3333, 0.3334);
}
function NumberStrictEqualsTrue() {
strictEquals(0.3333, 0.3333);
}
function StringStrictEqualsFalse() {
strictEquals("abc", "def");
}
function StringStrictEqualsTrue() {
strictEquals("abc", "abc");
}
function BooleanStrictEquals() {
strictEqualsBoolean("a");
strictEqualsBoolean(true);
strictEqualsBoolean(false);
}
function MixedStrictEquals() {
strictEquals(10, "10");
}
function SmiEqualsFalse() {
equals(10, 20);
}
function SmiEqualsTrue() {
equals(10, 10);
}
function NumberEqualsFalse() {
equals(0.3333, 0.3334);
}
function NumberEqualsTrue() {
equals(0.3333, 0.3333);
}
function StringEqualsFalse() {
equals("abc", "def");
}
function StringEqualsTrue() {
equals("abc", "abc");
}
function MixedEquals() {
equals(10, "10");
}
function ObjectEqualsNull(null_object) {
equals(null_object, null);
}
function SmiRelationalCompare() {
relationalCompare(10, 20);
}
function NumberRelationalCompare() {
relationalCompare(0.3333, 0.3334);
}
function StringRelationalCompare() {
relationalCompare("abc", "def");
}
function MixedRelationalCompare() {
relationalCompare(10, "10");
}

View File

@ -0,0 +1,29 @@
// Copyright 2014 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.
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js');
var success = true;
function PrintResult(name, result) {
print(name + '-BytecodeHandler(Score): ' + result);
}
function PrintStep(name) {}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });

View File

@ -0,0 +1,192 @@
// Copyright 2017 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('ShortString-StringConcat-2', ShortStringConcat2);
addBenchmark('ShortString-StringConcat-3', ShortStringConcat3);
addBenchmark('ShortString-StringConcat-5', ShortStringConcat5);
addBenchmark('ShortString-StringConcat-10', ShortStringConcat10);
addBenchmark('LongString-StringConcat-2', LongStringConcat2);
addBenchmark('LongString-StringConcat-3', LongStringConcat3);
addBenchmark('LongString-StringConcat-5', LongStringConcat5);
addBenchmark('LongString-StringConcat-10', LongStringConcat10);
addBenchmark('NumberString-StringConcat-2', NumberStringConcat2);
addBenchmark('NumberString-StringConcat-3', NumberStringConcat3);
addBenchmark('NumberString-StringConcat-5', NumberStringConcat5);
addBenchmark('NumberString-StringConcat-10', NumberStringConcat10);
function stringConcat2(a) {
for (var i = 0; i < 100; ++i) {
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
"s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a; "s" + a;
}
}
function stringConcat3(a, b) {
for (var i = 0; i < 100; ++i) {
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
"s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b; "s" + a + b;
}
}
function stringConcat5(a, b, c, d) {
for (var i = 0; i < 100; ++i) {
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
"s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d; "s" + a + b + c + d;
}
}
function stringConcat10(a, b, c, d, e, f, g, h, i) {
for (var j = 0; j < 100; ++j) {
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
"s" + a + b + c + d + e + f + g + h + i; "s" + a + b + c + d + e + f + g + h + i;
}
}
function ShortStringConcat2() {
stringConcat2("a");
}
function ShortStringConcat3() {
stringConcat3("a", "b");
}
function ShortStringConcat5() {
stringConcat5("a", "b", "c", "d");
}
function ShortStringConcat10() {
stringConcat10("a", "b", "c", "d", "e", "f", "g", "h", "i");
}
function LongStringConcat2() {
stringConcat2("long string over consmin");
}
function LongStringConcat3() {
stringConcat3("long string ", "over consmin");
}
function LongStringConcat5() {
stringConcat5("long ", "string ", "over ", "consmin");
}
function LongStringConcat10() {
stringConcat10("long ", "string ", "over ", "consmin ", "long ", "string ",
"over ", "consmin", "done");
}
function NumberStringConcat2() {
stringConcat2(123.456);
}
function NumberStringConcat3() {
stringConcat3(1, 0.2345);
}
function NumberStringConcat5() {
stringConcat5(1, 2, 3, 4.5, 5.6);
}
function NumberStringConcat10() {
stringConcat10(10, 2345, 5e10, 3.14, 987654321, 21.56789, 2, 3, 4);
}

View File

@ -0,0 +1,87 @@
{
"owners": ["caitp@igalia.com", "joyee@igalia.com"],
"name": "ClassFields",
"run_count": 3,
"run_count_arm": 1,
"run_count_arm64": 1,
"timeout": 120,
"timeout_arm64": 240,
"units": "score",
"total": true,
"resources": ["base.js"],
"flags": ["--allow-natives-syntax"],
"tests": [
{
"name": "EvaluateClassOpt",
"path": ["ClassFields"],
"test_flags": [ "evaluate-class", "opt" ],
"main": "run.js",
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"resources": ["classes.js", "evaluate-class.js"],
"tests": [
{"name": "EvaluateSinglePublicFieldClassOpt"},
{"name": "EvaluateMultiPublicFieldClassOpt"},
{"name": "EvaluateSinglePrivateFieldClassOpt"},
{"name": "EvaluateMultiPrivateFieldClassOpt"},
{"name": "EvaluateSinglePrivateMethodClassOpt"},
{"name": "EvaluateMultiPrivateMethodClassOpt"},
{"name": "EvaluateSingleComputedFieldClassOpt"},
{"name": "EvaluateMultiComputedFieldClassOpt"}
]
},
{
"name": "EvaluateClassNoOpt",
"path": ["ClassFields"],
"test_flags": [ "evaluate-class", "noopt" ],
"main": "run.js",
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"resources": ["classes.js", "evaluate-class.js"],
"tests": [
{"name": "EvaluateSinglePublicFieldClassNoOpt"},
{"name": "EvaluateMultiPublicFieldClassNoOpt"},
{"name": "EvaluateSinglePrivateFieldClassNoOpt"},
{"name": "EvaluateMultiPrivateFieldClassNoOpt"},
{"name": "EvaluateSinglePrivateMethodClassNoOpt"},
{"name": "EvaluateMultiPrivateMethodClassNoOpt"},
{"name": "EvaluateSingleComputedFieldClassNoOpt"},
{"name": "EvaluateMultiComputedFieldClassNoOpt"}
]
},
{
"name": "InitializeClassOpt",
"path": ["ClassFields"],
"test_flags": [ "initialize-instance", "opt" ],
"main": "run.js",
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"resources": ["classes.js", "initialize-instance.js"],
"tests": [
{"name": "InitializeSinglePublicFieldClassOpt"},
{"name": "InitializeMultiPublicFieldClassOpt"},
{"name": "InitializeSinglePrivateFieldClassOpt"},
{"name": "InitializeMultiPrivateFieldClassOpt"},
{"name": "InitializeSinglePrivateMethodClassOpt"},
{"name": "InitializeMultiPrivateMethodClassOpt"},
{"name": "InitializeSingleComputedFieldClassOpt"},
{"name": "InitializeMultiComputedFieldClassOpt"}
]
},
{
"name": "InitializeClassNoOpt",
"path": ["ClassFields"],
"test_flags": [ "initialize-instance", "noopt" ],
"main": "run.js",
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"resources": ["classes.js", "initialize-instance.js"],
"tests": [
{"name": "InitializeSinglePublicFieldClassNoOpt"},
{"name": "InitializeMultiPublicFieldClassNoOpt"},
{"name": "InitializeSinglePrivateFieldClassNoOpt"},
{"name": "InitializeMultiPrivateFieldClassNoOpt"},
{"name": "InitializeSinglePrivateMethodClassNoOpt"},
{"name": "InitializeMultiPrivateMethodClassNoOpt"},
{"name": "InitializeSingleComputedFieldClassNoOpt"},
{"name": "InitializeMultiComputedFieldClassNoOpt"}
]
}
]
}

View File

@ -0,0 +1,117 @@
// Copyright 2021 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.
"use strict";
let i = 0;
function EvaluateSinglePublicFieldClass() {
return class SinglePublicFieldClass {
x = i;
check() {
return this.x === i;
}
};
}
function EvaluateMultiPublicFieldClass() {
return class MultiPublicFieldClass {
x = i;
y = i+1;
z = i+2;
q = i+3;
r = i+4;
a = i+5;
check() {
return this.x + 1 === this.y && this.y + 1 === this.z &&
this.z + 1 === this.q && this.q + 1 === this.r &&
this.r + 1 === this.a;
}
};
}
function EvaluateSinglePrivateFieldClass() {
return class SinglePrivateFieldClass {
#x = i;
check() {
return this.#x === i;
}
}
}
function EvaluateMultiPrivateFieldClass() {
return class MultiPrivateFieldClass {
#x = i;
#y = i+1;
#z = i+2;
#q = i+3;
#r = i+4;
#a = i+5;
check() {
return this.#x + 1 === this.#y && this.#y + 1 === this.#z &&
this.#z + 1 === this.#q && this.#q + 1 === this.#r &&
this.#r + 1 === this.#a;
}
};
}
function EvaluateSinglePrivateMethodClass() {
return class PrivateSingleMethodClass {
#x() { return 0; }
check() {
return this.#x() === 0;
}
};
}
function EvaluateMultiPrivateMethodClass() {
return class PrivateMultiMethodClass {
#x() { return 0; }
#y() { return 1; }
#z() { return 2; }
#q() { return 3; }
#r() { return 4; }
#a() { return 5; }
check() {
return this.#x() + 1 === this.#y() && this.#y() + 1 === this.#z() &&
this.#z() + 1 === this.#q() && this.#q() + 1 === this.#r() &&
this.#r() + 1 === this.#a();
}
};
}
function key(i) {
return 'abcdefghijklmnopqrstuvwxyz'[i];
}
function EvaluateSingleComputedFieldClass() {
return class SingleComputedFieldClass {
[key(0)] = i;
check() {
return this[key(0)] === i;
}
}
}
function EvaluateMultiComputedFieldClass() {
return class MultiComputedFieldClass {
[key(0)] = i;
[key(1)] = i+1;
[key(2)] = i+2;
[key(3)] = i+3;
[key(4)] = i+4;
[key(5)] = i+5;
check() {
return this[key(0)] + 1 === this[key(1)] && this[key(1)] + 1 === this[key(2)] &&
this[key(2)] + 1 === this[key(3)] && this[key(3)] + 1 === this[key(4)] &&
this[key(4)] + 1 === this[key(5)];
}
};
}

View File

@ -0,0 +1,107 @@
// Copyright 2021 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.
'use strict';
d8.file.execute('classes.js');
function CreateBenchmark(name, optimize) {
let factory;
let array;
switch (name) {
case "EvaluateSinglePublicFieldClass":
factory = EvaluateSinglePublicFieldClass;
break;
case "EvaluateMultiPublicFieldClass":
factory = EvaluateMultiPublicFieldClass;
break;
case "EvaluateSinglePrivateFieldClass":
factory = EvaluateSinglePrivateFieldClass;
break;
case "EvaluateMultiPrivateFieldClass":
factory = EvaluateMultiPrivateFieldClass;
break;
case "EvaluateSinglePrivateMethodClass":
factory = EvaluateSinglePrivateMethodClass;
break;
case "EvaluateMultiPrivateMethodClass":
factory = EvaluateMultiPrivateMethodClass;
break;
case "EvaluateSingleComputedFieldClass":
factory = EvaluateSingleComputedFieldClass;
break;
case "EvaluateMultiComputedFieldClass":
factory = EvaluateMultiComputedFieldClass;
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
if (optimize) {
%PrepareFunctionForOptimization(factory);
} else {
%NeverOptimizeFunction(factory);
}
function setUp() {
array = [factory(), factory()];
// Populate the array first to reduce the impact of
// array allocations.
for (let i = 0; i < LOCAL_ITERATIONS - 2; ++i) {
array.push(array[0]);
}
if (optimize) {
%OptimizeFunctionOnNextCall(factory);
}
}
function runBenchmark() {
for (let i = 0; i < LOCAL_ITERATIONS; ++i) {
array[i] = factory();
}
}
function tearDown() {
if (array.length < 3) {
throw new Error(`Check failed, array length ${array.length}`);
}
for (const klass of array) {
const instance = new klass();
if (!instance.check())
throw new Error(`instance.check() failed`);
}
}
const DETERMINISTIC_RUNS = 1;
const LOCAL_ITERATIONS = 100;
const benchName = `${name}${optimize ? "Opt" : "NoOpt"}`
new BenchmarkSuite(benchName, [1000], [
new Benchmark(
benchName,
false, false, DETERMINISTIC_RUNS, runBenchmark, setUp, tearDown)
]);
}
let optimize;
switch (arguments[1]) {
case 'opt':
optimize = true;
break;
case 'noopt':
optimize = false;
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
CreateBenchmark("EvaluateSinglePublicFieldClass", optimize);
CreateBenchmark("EvaluateMultiPublicFieldClass", optimize);
CreateBenchmark("EvaluateSinglePrivateFieldClass", optimize);
CreateBenchmark("EvaluateMultiPrivateFieldClass", optimize);
CreateBenchmark("EvaluateSinglePrivateMethodClass", optimize);
CreateBenchmark("EvaluateMultiPrivateMethodClass", optimize);
CreateBenchmark("EvaluateSingleComputedFieldClass", optimize);
CreateBenchmark("EvaluateMultiComputedFieldClass", optimize);

View File

@ -0,0 +1,106 @@
// Copyright 2021 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.
'use strict';
d8.file.execute('classes.js');
function CreateBenchmark(name, optimize) {
let klass;
let array;
switch (name) {
case "InitializeSinglePublicFieldClass":
klass = EvaluateSinglePublicFieldClass();
break;
case "InitializeMultiPublicFieldClass":
klass = EvaluateMultiPublicFieldClass();
break;
case "InitializeSinglePrivateFieldClass":
klass = EvaluateSinglePrivateFieldClass();
break;
case "InitializeMultiPrivateFieldClass":
klass = EvaluateMultiPrivateFieldClass();
break;
case "InitializeSinglePrivateMethodClass":
klass = EvaluateSinglePrivateMethodClass();
break;
case "InitializeMultiPrivateMethodClass":
klass = EvaluateMultiPrivateMethodClass();
break;
case "InitializeSingleComputedFieldClass":
klass = EvaluateSingleComputedFieldClass();
break;
case "InitializeMultiComputedFieldClass":
klass = EvaluateMultiComputedFieldClass();
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
if (optimize) {
%PrepareFunctionForOptimization(klass);
} else {
%NeverOptimizeFunction(klass);
}
function setUp() {
array = [new klass(), new klass()];
// Populate the array first to reduce the impact of
// array allocations.
for (let i = 0; i < LOCAL_ITERATIONS - 2; ++i) {
array.push(array[0]);
}
if (optimize) {
%OptimizeFunctionOnNextCall(klass);
}
}
function runBenchmark() {
for (let i = 0; i < LOCAL_ITERATIONS; ++i) {
array[i] = new klass();
}
}
function tearDown() {
if (array.length < 3) {
throw new Error(`Check failed, array length ${array.length}`);
}
for (const instance of array) {
if (!instance.check())
throw new Error(`instance.check() failed`);
}
}
const DETERMINISTIC_RUNS = 1;
const LOCAL_ITERATIONS = 10000;
const benchName = `${name}${optimize ? "Opt" : "NoOpt"}`
new BenchmarkSuite(benchName, [1000], [
new Benchmark(
benchName,
false, false, DETERMINISTIC_RUNS, runBenchmark, setUp, tearDown)
]);
}
let optimize;
switch (arguments[1]) {
case 'opt':
optimize = true;
break;
case 'noopt':
optimize = false;
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
CreateBenchmark("InitializeSinglePublicFieldClass", optimize);
CreateBenchmark("InitializeMultiPublicFieldClass", optimize);
CreateBenchmark("InitializeSinglePrivateFieldClass", optimize);
CreateBenchmark("InitializeMultiPrivateFieldClass", optimize);
CreateBenchmark("InitializeSinglePrivateMethodClass", optimize);
CreateBenchmark("InitializeMultiPrivateMethodClass", optimize);
CreateBenchmark("InitializeSingleComputedFieldClass", optimize);
CreateBenchmark("InitializeMultiComputedFieldClass", optimize);

View File

@ -0,0 +1,25 @@
// Copyright 2021 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(arguments[0] + '.js');
var success = true;
function PrintResult(name, result, mean) {
print(`${name}-ClassFields(Score): ${result}`);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,33 @@
// Copyright 2014 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.
'use strict';
var DefaultConstructorBenchmark = new BenchmarkSuite('DefaultConstructor',
[100], [
new Benchmark('NoSuperClass', false, false, 0, NoSuperClass),
new Benchmark('WithSuperClass', false, false, 0, WithSuperClass),
new Benchmark('WithSuperClassArguments', false, false, 0,
WithSuperClassArguments),
]);
class BaseClass {}
class DerivedClass extends BaseClass {}
function NoSuperClass() {
return new BaseClass();
}
function WithSuperClass() {
return new DerivedClass();
}
function WithSuperClassArguments() {
return new DerivedClass(0, 1, 2, 3, 4);
}

View File

@ -0,0 +1,31 @@
// Copyright 2017 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.
'use strict';
var DefaultConstructorBenchmark = new BenchmarkSuite('LeafConstructors',
[100], [
new Benchmark('WithExplicitArguments', false, false, 0,
WithExplicitArguments),
]);
const Point = class Point {
constructor(x, y, z) { this.x = x; this.y = y; this.z = z; }
}
const klasses = [
class A extends Point { constructor(x, y, z) { super(x, y, z); } },
class B extends Point { constructor(x, y, z) { super(x, y, z); } },
class C extends Point { constructor(x, y, z) { super(x, y, z); } },
class D extends Point { constructor(x, y, z) { super(x, y, z); } },
class E extends Point { constructor(x, y, z) { super(x, y, z); } }
];
function WithExplicitArguments() {
let result = null;
for (const klass of klasses) {
result = new klass(0, 1, 2);
}
return result;
};

View File

@ -0,0 +1,29 @@
// Copyright 2014 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.
d8.file.execute('../base.js');
d8.file.execute('super.js');
d8.file.execute('default-constructor.js');
d8.file.execute('leaf-constructors.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Classes(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,57 @@
// Copyright 2014 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.
'use strict';
var SuperBenchmark = new BenchmarkSuite('Super', [100], [
new Benchmark('SuperMethodCall', false, false, 0, SuperMethodCall),
new Benchmark('SuperGetterCall', false, false, 0, SuperGetterCall),
new Benchmark('SuperSetterCall', false, false, 0, SuperSetterCall),
]);
class Base {
constructor() {}
get x() {
return this._x++;
}
set x(v) {
this._x += v;
return this._x;
}
f() {
return this._x++;
}
}
class Derived extends Base {
constructor() {
super();
this._x = 1;
}
SuperCall() {
return super.f();
}
GetterCall() {
return super.x;
}
SetterCall() {
return super.x = 5;
}
}
var derived = new Derived();
function SuperMethodCall() {
return derived.SuperCall();
}
function SuperGetterCall() {
return derived.GetterCall();
}
function SuperSetterCall() {
return derived.SetterCall();
}

View File

@ -0,0 +1,43 @@
// Copyright 2015 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.
new BenchmarkSuite('Closures', [1000], [
new Benchmark('ShortLivingClosures', false, false, 0,
ShortLivingClosures, ShortLivingClosuresSetup, ShortLivingClosuresTearDown)
]);
// ----------------------------------------------------------------------------
// The pattern is this example is very common in Node.js.
var fs = {
readFile: function(filename, cb) {
cb(null, {length: 12});
}
};
function printLength (filename) {
fs.readFile(filename, foo);
function foo (err, buf) {
if (err) return;
for (var j = 0; j<1000; j++) {
// Do some work to make the optimization actually worth while
buf.length++;
}
return (buf.length);
}
}
function ShortLivingClosuresSetup() {}
function ShortLivingClosures() {
result = printLength('foo_bar.js');
}
function ShortLivingClosuresTearDown() {
return result == 1012;
}

View File

@ -0,0 +1,26 @@
// Copyright 2015 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.
d8.file.execute('../base.js');
d8.file.execute('closures.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Closures(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,48 @@
// Copyright 2014 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.
var N = 10;
var LargeN = 1e4;
var keys;
var keyValuePairs;
function SetupKeyValuePairsFromKeys() {
keyValuePairs = keys.map((v) => [v, v]);
}
function SetupSmiKeys(count = 2 * N) {
keys = Array.from({ length : count }, (v, i) => i);
}
function SetupSmiKeyValuePairs(count = 2 * N) {
SetupSmiKeys(count);
SetupKeyValuePairsFromKeys();
}
function SetupStringKeys(count = 2 * N) {
keys = Array.from({ length : count }, (v, i) => 's' + i);
}
function SetupStringKeyValuePairs(count = 2 * N) {
SetupStringKeys(count);
SetupKeyValuePairsFromKeys();
}
function SetupObjectKeys(count = 2 * N) {
keys = Array.from({ length : count }, (v, i) => ({}));
}
function SetupObjectKeyValuePairs(count = 2 * N) {
SetupObjectKeys(count);
SetupKeyValuePairsFromKeys();
}
function SetupDoubleKeys(count = 2 * N) {
keys = Array.from({ length : count }, (v, i) => i + 0.234);
}
function SetupDoubleKeyValuePairs(count = 2 * N) {
SetupDoubleKeys(count);
SetupKeyValuePairsFromKeys();
}

View File

@ -0,0 +1,315 @@
// Copyright 2014 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.
var MapSmiBenchmark = new BenchmarkSuite('Map-Smi', [1000], [
new Benchmark('Set', false, false, 0, MapSetSmi, MapSetupSmiBase, MapTearDown),
new Benchmark('Has', false, false, 0, MapHasSmi, MapSetupSmi, MapTearDown),
new Benchmark('Get', false, false, 0, MapGetSmi, MapSetupSmi, MapTearDown),
new Benchmark('Delete', false, false, 0, MapDeleteSmi, MapSetupSmi, MapTearDown),
]);
var MapStringBenchmark = new BenchmarkSuite('Map-String', [1000], [
new Benchmark('Set', false, false, 0, MapSetString, MapSetupStringBase, MapTearDown),
new Benchmark('Has', false, false, 0, MapHasString, MapSetupString, MapTearDown),
new Benchmark('Get', false, false, 0, MapGetString, MapSetupString, MapTearDown),
new Benchmark('Delete', false, false, 0, MapDeleteString, MapSetupString, MapTearDown),
]);
var MapObjectBenchmark = new BenchmarkSuite('Map-Object', [1000], [
new Benchmark('Set', false, false, 0, MapSetObject, MapSetupObjectBase, MapTearDown),
new Benchmark('Has', false, false, 0, MapHasObject, MapSetupObject, MapTearDown),
new Benchmark('Get', false, false, 0, MapGetObject, MapSetupObject, MapTearDown),
new Benchmark('Delete', false, false, 0, MapDeleteObject, MapSetupObject, MapTearDown),
]);
var MapDoubleBenchmark = new BenchmarkSuite('Map-Double', [1000], [
new Benchmark('Set', false, false, 0, MapSetDouble, MapSetupDoubleBase, MapTearDown),
new Benchmark('Has', false, false, 0, MapHasDouble, MapSetupDouble, MapTearDown),
new Benchmark('Get', false, false, 0, MapGetDouble, MapSetupDouble, MapTearDown),
new Benchmark('Delete', false, false, 0, MapDeleteDouble, MapSetupDouble, MapTearDown),
]);
var MapObjectLargeBenchmark = new BenchmarkSuite('Map-Object-Set-Get-Large', [1e7], [
new Benchmark('Set-Get', false, false, 0, MapSetGetObjectLarge,
MapSetupObjectBaseLarge, MapTearDown),
]);
var MapIterationBenchmark = new BenchmarkSuite('Map-Iteration', [1000], [
new Benchmark('ForEach', false, false, 0, MapForEach, MapSetupSmi, MapTearDown),
]);
var MapIterationBenchmark = new BenchmarkSuite('Map-Iterator', [1000], [
new Benchmark('Iterator', false, false, 0, MapIterator, MapSetupSmi, MapTearDown),
]);
var MapConstructorBenchmark = new BenchmarkSuite('Map-Constructor', [1000], [
new Benchmark('Smi', false, false, 0, MapConstructorSmi, SetupSmiKeyValuePairs, MapTearDown),
new Benchmark('String', false, false, 0, MapConstructorString, SetupStringKeyValuePairs, MapTearDown),
new Benchmark('Object', false, false, 0, MapConstructorObject, SetupObjectKeyValuePairs, MapTearDown),
new Benchmark('Double', false, false, 0, MapConstructorDouble, SetupDoubleKeyValuePairs, MapTearDown),
]);
var map;
function MapSetupSmiBase() {
SetupSmiKeys();
map = new Map;
}
function MapSetupSmi() {
MapSetupSmiBase();
MapSetSmi();
}
function MapSetupStringBase() {
SetupStringKeys();
map = new Map;
}
function MapSetupString() {
MapSetupStringBase();
MapSetString();
}
function MapSetupObjectBase() {
SetupObjectKeys();
map = new Map;
}
function MapSetupObjectBaseLarge() {
SetupObjectKeys(2 * LargeN);
map = new Map;
}
function MapSetupObject() {
MapSetupObjectBase();
MapSetObject();
}
function MapSetupDoubleBase() {
SetupDoubleKeys();
map = new Map;
}
function MapSetupDouble() {
MapSetupDoubleBase();
MapSetDouble();
}
function MapTearDown() {
map = null;
}
function MapConstructorSmi() {
map = new Map(keyValuePairs);
}
function MapSetSmi() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
}
}
function MapHasSmi() {
for (var i = 0; i < N; i++) {
if (!map.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.has(keys[i])) {
throw new Error();
}
}
}
function MapGetSmi() {
for (var i = 0; i < N; i++) {
if (map.get(keys[i]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.get(keys[i]) !== undefined) {
throw new Error();
}
}
}
function MapDeleteSmi() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
map.delete(keys[i]);
}
}
function MapConstructorString() {
map = new Map(keyValuePairs);
}
function MapSetString() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
}
}
function MapHasString() {
for (var i = 0; i < N; i++) {
if (!map.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.has(keys[i])) {
throw new Error();
}
}
}
function MapGetString() {
for (var i = 0; i < N; i++) {
if (map.get(keys[i]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.get(keys[i]) !== undefined) {
throw new Error();
}
}
}
function MapDeleteString() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
map.delete(keys[i]);
}
}
function MapConstructorObject() {
map = new Map(keyValuePairs);
}
function MapSetObject() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
}
}
function MapHasObject() {
for (var i = 0; i < N; i++) {
if (!map.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.has(keys[i])) {
throw new Error();
}
}
}
function MapGetObject() {
for (var i = 0; i < N; i++) {
if (map.get(keys[i]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.get(keys[i]) !== undefined) {
throw new Error();
}
}
}
function MapSetGetObjectLarge() {
for (var i = 0; i < LargeN; i++) {
map.set(keys[i * 2], i);
}
for (var i = 0; i < LargeN; i++) {
if (map.get(keys[i * 2]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * LargeN; i++) {
if (map.get(keys[i * 2 + 1]) !== undefined) {
throw new Error();
}
}
}
function MapDeleteObject() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
map.delete(keys[i]);
}
}
function MapConstructorDouble() {
map = new Map(keyValuePairs);
}
function MapSetDouble() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
}
}
function MapHasDouble() {
for (var i = 0; i < N; i++) {
if (!map.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.has(keys[i])) {
throw new Error();
}
}
}
function MapGetDouble() {
for (var i = 0; i < N; i++) {
if (map.get(keys[i]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (map.get(keys[i]) !== undefined) {
throw new Error();
}
}
}
function MapDeleteDouble() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
map.delete(keys[i]);
}
}
function MapForEach() {
map.forEach(function(v, k) {
if (v !== k) {
throw new Error();
}
});
}
function MapIterator() {
var result = 0;
for (const v of map.values()) result += v;
return result;
}

View File

@ -0,0 +1,32 @@
// Copyright 2014 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.
"use strict";
d8.file.execute('../base.js');
d8.file.execute('common.js');
d8.file.execute('map.js');
d8.file.execute('set.js');
d8.file.execute('weakmap.js');
d8.file.execute('weakset.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Collections(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,260 @@
// Copyright 2014 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.
var SetSmiBenchmark = new BenchmarkSuite('Set-Smi', [1000], [
new Benchmark('Set', false, false, 0, SetAddSmi, SetSetupSmiBase, SetTearDown),
new Benchmark('Has', false, false, 0, SetHasSmi, SetSetupSmi, SetTearDown),
new Benchmark('Delete', false, false, 0, SetDeleteSmi, SetSetupSmi, SetTearDown),
]);
var SetStringBenchmark = new BenchmarkSuite('Set-String', [1000], [
new Benchmark('Set', false, false, 0, SetAddString, SetSetupStringBase, SetTearDown),
new Benchmark('Has', false, false, 0, SetHasString, SetSetupString, SetTearDown),
new Benchmark('Delete', false, false, 0, SetDeleteString, SetSetupString, SetTearDown),
]);
var SetObjectBenchmark = new BenchmarkSuite('Set-Object', [1000], [
new Benchmark('Set', false, false, 0, SetAddObject, SetSetupObjectBase, SetTearDown),
new Benchmark('Has', false, false, 0, SetHasObject, SetSetupObject, SetTearDown),
new Benchmark('Delete', false, false, 0, SetDeleteObject, SetSetupObject, SetTearDown),
]);
var SetDoubleBenchmark = new BenchmarkSuite('Set-Double', [1000], [
new Benchmark('Set', false, false, 0, SetAddDouble, SetSetupDoubleBase, SetTearDown),
new Benchmark('Has', false, false, 0, SetHasDouble, SetSetupDouble, SetTearDown),
new Benchmark('Delete', false, false, 0, SetDeleteDouble, SetSetupDouble, SetTearDown),
]);
var SetIterationBenchmark = new BenchmarkSuite('Set-Iteration', [1000], [
new Benchmark('ForEach', false, false, 0, SetForEach, SetSetupSmi, SetTearDown),
]);
var SetIterationBenchmark = new BenchmarkSuite('Set-Iterator', [1000], [
new Benchmark('Iterator', false, false, 0, SetIterator, SetSetupSmi, SetTearDown),
]);
var SetConstructorBenchmark = new BenchmarkSuite('Set-Constructor', [1000], [
new Benchmark('Smi', false, false, 0, SetConstructorSmi, SetupSmiKeys, SetTearDown),
new Benchmark('String', false, false, 0, SetConstructorString, SetupStringKeys, SetTearDown),
new Benchmark('Object', false, false, 0, SetConstructorObject, SetupObjectKeys, SetTearDown),
new Benchmark('Double', false, false, 0, SetConstructorDouble, SetupDoubleKeys, SetTearDown),
]);
var set;
function SetSetupSmiBase() {
SetupSmiKeys();
set = new Set;
}
function SetSetupSmi() {
SetSetupSmiBase();
SetAddSmi();
}
function SetSetupStringBase() {
SetupStringKeys();
set = new Set;
}
function SetSetupString() {
SetSetupStringBase();
SetAddString();
}
function SetSetupObjectBase() {
SetupObjectKeys();
set = new Set;
}
function SetSetupObject() {
SetSetupObjectBase();
SetAddObject();
}
function SetSetupDoubleBase() {
SetupDoubleKeys();
set = new Set;
}
function SetSetupDouble() {
SetSetupDoubleBase();
SetAddDouble();
}
function SetTearDown() {
set = null;
}
function SetConstructorSmi() {
set = new Set(keys);
}
function SetAddSmi() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
}
}
function SetHasSmi() {
for (var i = 0; i < N; i++) {
if (!set.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (set.has(keys[i])) {
throw new Error();
}
}
}
function SetDeleteSmi() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
set.delete(keys[i]);
}
}
function SetConstructorString() {
set = new Set(keys);
}
function SetAddString() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
}
}
function SetHasString() {
for (var i = 0; i < N; i++) {
if (!set.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (set.has(keys[i])) {
throw new Error();
}
}
}
function SetDeleteString() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
set.delete(keys[i]);
}
}
function SetConstructorObject() {
set = new Set(keys);
}
function SetAddObject() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
}
}
function SetHasObject() {
for (var i = 0; i < N; i++) {
if (!set.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (set.has(keys[i])) {
throw new Error();
}
}
}
function SetDeleteObject() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
set.delete(keys[i]);
}
}
function SetConstructorDouble() {
set = new Set(keys);
}
function SetAddDouble() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
}
}
function SetHasDouble() {
for (var i = 0; i < N; i++) {
if (!set.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (set.has(keys[i])) {
throw new Error();
}
}
}
function SetDeleteDouble() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
set.delete(keys[i]);
}
}
function SetForEach() {
set.forEach(function(v, k) {
if (v !== k) {
throw new Error();
}
});
}
function SetIterator() {
var result = 0;
for (const v of set) result += v;
return result;
}

View File

@ -0,0 +1,131 @@
// Copyright 2014 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.
var MapBenchmark = new BenchmarkSuite('WeakMap', [1000], [
new Benchmark('Set', false, false, 0, WeakMapSet, WeakMapSetupBase,
WeakMapTearDown),
new Benchmark('Has', false, false, 0, WeakMapHas, WeakMapSetup,
WeakMapTearDown),
new Benchmark('Get', false, false, 0, WeakMapGet, WeakMapSetup,
WeakMapTearDown),
new Benchmark('Delete', false, false, 0, WeakMapDelete, WeakMapSetup,
WeakMapTearDown),
]);
var MapBenchmark = new BenchmarkSuite('WeakMapSetGet-Large', [1e7], [
new Benchmark('Set-Get', false, true, 1, WeakMapSetGetLarge,
WeakMapSetupBaseLarge, WeakMapTearDown),
]);
var MapBenchmark = new BenchmarkSuite('WeakMapSet-Huge', [1e8], [
new Benchmark('Set-Get', false, true, 1, WeakMapSetHuge,
WeakMapSetupBaseLarge, WeakMapTearDown),
]);
var MapBenchmark = new BenchmarkSuite('WeakMap-Constructor', [1000], [
new Benchmark('Constructor', false, false, 0, WeakMapConstructor, SetupObjectKeyValuePairs,
WeakMapTearDown),
]);
var wm;
function WeakMapSetupBase() {
SetupObjectKeys();
wm = new WeakMap;
}
function WeakMapSetupBaseLarge() {
SetupObjectKeys(2 * LargeN);
wm = new WeakMap;
}
function WeakMapSetup() {
WeakMapSetupBase();
WeakMapSet();
}
function WeakMapTearDown() {
wm = null;
}
function WeakMapConstructor() {
wm = new WeakMap(keyValuePairs);
}
function WeakMapSet() {
for (var i = 0; i < N; i++) {
wm.set(keys[i], i);
}
}
function WeakMapHas() {
for (var i = 0; i < N; i++) {
if (!wm.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (wm.has(keys[i])) {
throw new Error();
}
}
}
function WeakMapGet() {
for (var i = 0; i < N; i++) {
if (wm.get(keys[i]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (wm.get(keys[i]) !== undefined) {
throw new Error();
}
}
}
function WeakMapDelete() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not check the return value of delete.
for (var i = 0; i < N; i++) {
wm.delete(keys[i]);
}
}
function WeakMapSetGetLarge() {
for (var i = 0; i < LargeN; i++) {
wm.set(keys[i * 2], i);
}
for (var i = 0; i < LargeN; i++) {
if (wm.get(keys[i * 2]) !== i) {
throw new Error();
}
}
for (var i = N; i < 2 * LargeN; i++) {
if (wm.get(keys[i * 2 + 1]) !== undefined) {
throw new Error();
}
}
}
function WeakMapSetHuge() {
function Foo(i) {
this.x = i;
}
let obj;
for (let i = 0; i < LargeN; i++) {
obj = new Foo(i); // Make sure we do not scalar-replace the object.
wm.set(obj, 1);
}
}

View File

@ -0,0 +1,72 @@
// Copyright 2014 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.
var SetBenchmark = new BenchmarkSuite('WeakSet', [1000], [
new Benchmark('Add', false, false, 0, WeakSetAdd, WeakSetSetupBase,
WeakSetTearDown),
new Benchmark('Has', false, false, 0, WeakSetHas, WeakSetSetup,
WeakSetTearDown),
new Benchmark('Delete', false, false, 0, WeakSetDelete, WeakSetSetup,
WeakSetTearDown),
]);
var SetBenchmark = new BenchmarkSuite('WeakSet-Constructor', [1000], [
new Benchmark('Constructor', false, false, 0, WeakSetConstructor, SetupObjectKeys,
WeakSetTearDown),
]);
var ws;
function WeakSetSetupBase() {
SetupObjectKeys();
ws = new WeakSet;
}
function WeakSetSetup() {
WeakSetSetupBase();
WeakSetAdd();
}
function WeakSetTearDown() {
ws = null;
}
function WeakSetConstructor() {
ws = new WeakSet(keys);
}
function WeakSetAdd() {
for (var i = 0; i < N; i++) {
ws.add(keys[i]);
}
}
function WeakSetHas() {
for (var i = 0; i < N; i++) {
if (!ws.has(keys[i])) {
throw new Error();
}
}
for (var i = N; i < 2 * N; i++) {
if (ws.has(keys[i])) {
throw new Error();
}
}
}
function WeakSetDelete() {
// This is run more than once per setup so we will end up deleting items
// more than once. Therefore, we do not the return value of delete.
for (var i = 0; i < N; i++) {
ws.delete(keys[i]);
}
}

View File

@ -0,0 +1,528 @@
// Copyright 2023 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.
(() => {
let a = 19, b = 3;
let i = {};
function copy() {
let o = {};
o.a0 = i.a0;
o.a1 = i.a1;
o.a2 = i.a2;
o.a3 = i.a3;
o.a4 = i.a4;
o.a5 = i.a5;
o.a6 = i.a6;
o.a7 = i.a7;
o.a8 = i.a8;
o.a9 = i.a9;
o.a10 = i.a10;
o.a11 = i.a11;
o.a12 = i.a12;
o.a13 = i.a13;
o.a14 = i.a14;
o.a15 = i.a15;
o.a16 = i.a16;
o.a17 = i.a17;
o.a18 = i.a18;
o.a19 = i.a19;
o.a20 = i.a20;
o.a21 = i.a21;
o.a22 = i.a22;
o.a23 = i.a23;
o.a24 = i.a24;
o.a25 = i.a25;
o.a26 = i.a26;
o.a27 = i.a27;
o.a28 = i.a28;
o.a29 = i.a29;
o.a30 = i.a30;
o.a31 = i.a31;
o.a32 = i.a32;
o.a33 = i.a33;
o.a34 = i.a34;
o.a35 = i.a35;
o.a36 = i.a36;
o.a37 = i.a37;
o.a38 = i.a38;
o.a39 = i.a39;
o.a40 = i.a40;
o.a41 = i.a41;
o.a42 = i.a42;
o.a43 = i.a43;
o.a44 = i.a44;
o.a45 = i.a45;
o.a46 = i.a46;
o.a47 = i.a47;
o.a48 = i.a48;
o.a49 = i.a49;
o.a50 = i.a50;
o.a51 = i.a51;
o.a52 = i.a52;
o.a53 = i.a53;
o.a54 = i.a54;
o.a55 = i.a55;
o.a56 = i.a56;
o.a57 = i.a57;
o.a58 = i.a58;
o.a59 = i.a59;
o.a60 = i.a60;
o.a61 = i.a61;
o.a62 = i.a62;
o.a63 = i.a63;
o.a64 = i.a64;
o.a65 = i.a65;
o.a66 = i.a66;
o.a67 = i.a67;
o.a68 = i.a68;
o.a69 = i.a69;
o.a70 = i.a70;
o.a71 = i.a71;
o.a72 = i.a72;
o.a73 = i.a73;
o.a74 = i.a74;
o.a75 = i.a75;
o.a76 = i.a76;
o.a77 = i.a77;
o.a78 = i.a78;
o.a79 = i.a79;
o.a80 = i.a80;
o.a81 = i.a81;
o.a82 = i.a82;
o.a83 = i.a83;
o.a84 = i.a84;
o.a85 = i.a85;
o.a86 = i.a86;
o.a87 = i.a87;
o.a88 = i.a88;
o.a89 = i.a89;
o.a90 = i.a90;
o.a91 = i.a91;
o.a92 = i.a92;
o.a93 = i.a93;
o.a94 = i.a94;
o.a95 = i.a95;
o.a96 = i.a96;
o.a97 = i.a97;
o.a98 = i.a98;
o.a99 = i.a99;
o.a100 = i.a100;
o.a101 = i.a101;
o.a102 = i.a102;
o.a103 = i.a103;
o.a104 = i.a104;
o.a105 = i.a105;
o.a106 = i.a106;
o.a107 = i.a107;
o.a108 = i.a108;
o.a109 = i.a109;
o.a110 = i.a110;
o.a111 = i.a111;
o.a112 = i.a112;
o.a113 = i.a113;
o.a114 = i.a114;
o.a115 = i.a115;
o.a116 = i.a116;
o.a117 = i.a117;
o.a118 = i.a118;
o.a119 = i.a119;
o.a120 = i.a120;
o.a121 = i.a121;
o.a122 = i.a122;
o.a123 = i.a123;
o.a124 = i.a124;
o.a125 = i.a125;
o.a126 = i.a126;
o.a127 = i.a127;
o.a128 = i.a128;
o.a129 = i.a129;
o.a130 = i.a130;
o.a131 = i.a131;
o.a132 = i.a132;
o.a133 = i.a133;
o.a134 = i.a134;
o.a135 = i.a135;
o.a136 = i.a136;
o.a137 = i.a137;
o.a138 = i.a138;
o.a139 = i.a139;
o.a140 = i.a140;
o.a141 = i.a141;
o.a142 = i.a142;
o.a143 = i.a143;
o.a144 = i.a144;
o.a145 = i.a145;
o.a146 = i.a146;
o.a147 = i.a147;
o.a148 = i.a148;
o.a149 = i.a149;
o.a150 = i.a150;
o.a151 = i.a151;
o.a152 = i.a152;
o.a153 = i.a153;
o.a154 = i.a154;
o.a155 = i.a155;
o.a156 = i.a156;
o.a157 = i.a157;
o.a158 = i.a158;
o.a159 = i.a159;
o.a160 = i.a160;
o.a161 = i.a161;
o.a162 = i.a162;
o.a163 = i.a163;
o.a164 = i.a164;
o.a165 = i.a165;
o.a166 = i.a166;
o.a167 = i.a167;
o.a168 = i.a168;
o.a169 = i.a169;
o.a170 = i.a170;
o.a171 = i.a171;
o.a172 = i.a172;
o.a173 = i.a173;
o.a174 = i.a174;
o.a175 = i.a175;
o.a176 = i.a176;
o.a177 = i.a177;
o.a178 = i.a178;
o.a179 = i.a179;
o.a180 = i.a180;
o.a181 = i.a181;
o.a182 = i.a182;
o.a183 = i.a183;
o.a184 = i.a184;
o.a185 = i.a185;
o.a186 = i.a186;
o.a187 = i.a187;
o.a188 = i.a188;
o.a189 = i.a189;
o.a190 = i.a190;
o.a191 = i.a191;
o.a192 = i.a192;
o.a193 = i.a193;
o.a194 = i.a194;
o.a195 = i.a195;
o.a196 = i.a196;
o.a197 = i.a197;
o.a198 = i.a198;
o.a199 = i.a199;
o.a200 = i.a200;
o.a201 = i.a201;
o.a202 = i.a202;
o.a203 = i.a203;
o.a204 = i.a204;
o.a205 = i.a205;
o.a206 = i.a206;
o.a207 = i.a207;
o.a208 = i.a208;
o.a209 = i.a209;
o.a210 = i.a210;
o.a211 = i.a211;
o.a212 = i.a212;
o.a213 = i.a213;
o.a214 = i.a214;
o.a215 = i.a215;
o.a216 = i.a216;
o.a217 = i.a217;
o.a218 = i.a218;
o.a219 = i.a219;
o.a220 = i.a220;
o.a221 = i.a221;
o.a222 = i.a222;
o.a223 = i.a223;
o.a224 = i.a224;
o.a225 = i.a225;
o.a226 = i.a226;
o.a227 = i.a227;
o.a228 = i.a228;
o.a229 = i.a229;
o.a230 = i.a230;
o.a231 = i.a231;
o.a232 = i.a232;
o.a233 = i.a233;
o.a234 = i.a234;
o.a235 = i.a235;
o.a236 = i.a236;
o.a237 = i.a237;
o.a238 = i.a238;
o.a239 = i.a239;
o.a240 = i.a240;
o.a241 = i.a241;
o.a242 = i.a242;
o.a243 = i.a243;
o.a244 = i.a244;
o.a245 = i.a245;
o.a246 = i.a246;
o.a247 = i.a247;
o.a248 = i.a248;
o.a249 = i.a249;
o.a250 = i.a250;
o.a251 = i.a251;
o.a252 = i.a252;
o.a253 = i.a253;
o.a254 = i.a254;
o.a255 = i.a255;
o.a256 = i.a256;
o.a257 = i.a257;
o.a258 = i.a258;
o.a259 = i.a259;
o.a260 = i.a260;
o.a261 = i.a261;
o.a262 = i.a262;
o.a263 = i.a263;
o.a264 = i.a264;
o.a265 = i.a265;
o.a266 = i.a266;
o.a267 = i.a267;
o.a268 = i.a268;
o.a269 = i.a269;
o.a270 = i.a270;
o.a271 = i.a271;
o.a272 = i.a272;
o.a273 = i.a273;
o.a274 = i.a274;
o.a275 = i.a275;
o.a276 = i.a276;
o.a277 = i.a277;
o.a278 = i.a278;
o.a279 = i.a279;
o.a280 = i.a280;
o.a281 = i.a281;
o.a282 = i.a282;
o.a283 = i.a283;
o.a284 = i.a284;
o.a285 = i.a285;
o.a286 = i.a286;
o.a287 = i.a287;
o.a288 = i.a288;
o.a289 = i.a289;
o.a290 = i.a290;
o.a291 = i.a291;
o.a292 = i.a292;
o.a293 = i.a293;
o.a294 = i.a294;
o.a295 = i.a295;
o.a296 = i.a296;
o.a297 = i.a297;
o.a298 = i.a298;
o.a299 = i.a299;
o.a300 = i.a300;
o.a301 = i.a301;
o.a302 = i.a302;
o.a303 = i.a303;
o.a304 = i.a304;
o.a305 = i.a305;
o.a306 = i.a306;
o.a307 = i.a307;
o.a308 = i.a308;
o.a309 = i.a309;
o.a310 = i.a310;
o.a311 = i.a311;
o.a312 = i.a312;
o.a313 = i.a313;
o.a314 = i.a314;
o.a315 = i.a315;
o.a316 = i.a316;
o.a317 = i.a317;
o.a318 = i.a318;
o.a319 = i.a319;
o.a320 = i.a320;
o.a321 = i.a321;
o.a322 = i.a322;
o.a323 = i.a323;
o.a324 = i.a324;
o.a325 = i.a325;
o.a326 = i.a326;
o.a327 = i.a327;
o.a328 = i.a328;
o.a329 = i.a329;
o.a330 = i.a330;
o.a331 = i.a331;
o.a332 = i.a332;
o.a333 = i.a333;
o.a334 = i.a334;
o.a335 = i.a335;
o.a336 = i.a336;
o.a337 = i.a337;
o.a338 = i.a338;
o.a339 = i.a339;
o.a340 = i.a340;
o.a341 = i.a341;
o.a342 = i.a342;
o.a343 = i.a343;
o.a344 = i.a344;
o.a345 = i.a345;
o.a346 = i.a346;
o.a347 = i.a347;
o.a348 = i.a348;
o.a349 = i.a349;
o.a350 = i.a350;
o.a351 = i.a351;
o.a352 = i.a352;
o.a353 = i.a353;
o.a354 = i.a354;
o.a355 = i.a355;
o.a356 = i.a356;
o.a357 = i.a357;
o.a358 = i.a358;
o.a359 = i.a359;
o.a360 = i.a360;
o.a361 = i.a361;
o.a362 = i.a362;
o.a363 = i.a363;
o.a364 = i.a364;
o.a365 = i.a365;
o.a366 = i.a366;
o.a367 = i.a367;
o.a368 = i.a368;
o.a369 = i.a369;
o.a370 = i.a370;
o.a371 = i.a371;
o.a372 = i.a372;
o.a373 = i.a373;
o.a374 = i.a374;
o.a375 = i.a375;
o.a376 = i.a376;
o.a377 = i.a377;
o.a378 = i.a378;
o.a379 = i.a379;
o.a380 = i.a380;
o.a381 = i.a381;
o.a382 = i.a382;
o.a383 = i.a383;
o.a384 = i.a384;
o.a385 = i.a385;
o.a386 = i.a386;
o.a387 = i.a387;
o.a388 = i.a388;
o.a389 = i.a389;
o.a390 = i.a390;
o.a391 = i.a391;
o.a392 = i.a392;
o.a393 = i.a393;
o.a394 = i.a394;
o.a395 = i.a395;
o.a396 = i.a396;
o.a397 = i.a397;
o.a398 = i.a398;
o.a399 = i.a399;
o.a400 = i.a400;
o.a401 = i.a401;
o.a402 = i.a402;
o.a403 = i.a403;
o.a404 = i.a404;
o.a405 = i.a405;
o.a406 = i.a406;
o.a407 = i.a407;
o.a408 = i.a408;
o.a409 = i.a409;
o.a410 = i.a410;
o.a411 = i.a411;
o.a412 = i.a412;
o.a413 = i.a413;
o.a414 = i.a414;
o.a415 = i.a415;
o.a416 = i.a416;
o.a417 = i.a417;
o.a418 = i.a418;
o.a419 = i.a419;
o.a420 = i.a420;
o.a421 = i.a421;
o.a422 = i.a422;
o.a423 = i.a423;
o.a424 = i.a424;
o.a425 = i.a425;
o.a426 = i.a426;
o.a427 = i.a427;
o.a428 = i.a428;
o.a429 = i.a429;
o.a430 = i.a430;
o.a431 = i.a431;
o.a432 = i.a432;
o.a433 = i.a433;
o.a434 = i.a434;
o.a435 = i.a435;
o.a436 = i.a436;
o.a437 = i.a437;
o.a438 = i.a438;
o.a439 = i.a439;
o.a440 = i.a440;
o.a441 = i.a441;
o.a442 = i.a442;
o.a443 = i.a443;
o.a444 = i.a444;
o.a445 = i.a445;
o.a446 = i.a446;
o.a447 = i.a447;
o.a448 = i.a448;
o.a449 = i.a449;
o.a450 = i.a450;
o.a451 = i.a451;
o.a452 = i.a452;
o.a453 = i.a453;
o.a454 = i.a454;
o.a455 = i.a455;
o.a456 = i.a456;
o.a457 = i.a457;
o.a458 = i.a458;
o.a459 = i.a459;
o.a460 = i.a460;
o.a461 = i.a461;
o.a462 = i.a462;
o.a463 = i.a463;
o.a464 = i.a464;
o.a465 = i.a465;
o.a466 = i.a466;
o.a467 = i.a467;
o.a468 = i.a468;
o.a469 = i.a469;
o.a470 = i.a470;
o.a471 = i.a471;
o.a472 = i.a472;
o.a473 = i.a473;
o.a474 = i.a474;
o.a475 = i.a475;
o.a476 = i.a476;
o.a477 = i.a477;
o.a478 = i.a478;
o.a479 = i.a479;
o.a480 = i.a480;
o.a481 = i.a481;
o.a482 = i.a482;
o.a483 = i.a483;
o.a484 = i.a484;
o.a485 = i.a485;
o.a486 = i.a486;
o.a487 = i.a487;
o.a488 = i.a488;
o.a489 = i.a489;
o.a490 = i.a490;
o.a491 = i.a491;
o.a492 = i.a492;
o.a493 = i.a493;
o.a494 = i.a494;
o.a495 = i.a495;
o.a496 = i.a496;
o.a497 = i.a497;
o.a498 = i.a498;
o.a499 = i.a499;
o.a500 = i.a500;
return o;
}
// Initializing feedback for each function
%PrepareFunctionForOptimization(copy);
i = copy();
copy();
// Creating runners
function run_copy() {
%BenchTurbofan(copy, 1);
}
// Registering tests
createSuite('Large-Copy', 1, run_copy);
})();

View File

@ -0,0 +1,103 @@
// Copyright 2023 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.
(() => {
let a = 19, b = 3;
let i = {};
function copy() {
let o = {};
o.a0 = i.a0;
o.a1 = i.a1;
o.a2 = i.a2;
o.a3 = i.a3;
o.a4 = i.a4;
o.a5 = i.a5;
o.a6 = i.a6;
o.a7 = i.a7;
o.a8 = i.a8;
o.a9 = i.a9;
o.a10 = i.a10;
o.a11 = i.a11;
o.a12 = i.a12;
o.a13 = i.a13;
o.a14 = i.a14;
o.a15 = i.a15;
o.a16 = i.a16;
o.a17 = i.a11;
o.a18 = i.a18;
o.a19 = i.a19;
return o;
}
function fact() {
let i = a;
let r = 1;
while (i != 0) {
r *= i;
i--;
}
return i;
}
function is_prime() {
for (let i = 2; i <= Math.sqrt(a); i++) {
if (a % i == 0) return false;
}
return true;
}
function eratosthenes(max) {
let nums = new Array(max).fill(false);
nums[0] = nums[1] = true;
for (let i = 2; i <= Math.sqrt(max); i++) {
if (nums[i]) continue;
for (var j = i * i; j < max; j += i) {
nums[j] = true;
}
}
return nums;
}
// Initializing feedback for each function
%PrepareFunctionForOptimization(copy);
i = copy();
copy();
%PrepareFunctionForOptimization(fact);
fact();
a = 29;
fact();
%PrepareFunctionForOptimization(is_prime);
is_prime();
a = 23;
is_prime();
a = 25;
is_prime();
%PrepareFunctionForOptimization(eratosthenes);
eratosthenes(1000);
// Creating runners
function run_copy() {
%BenchTurbofan(copy, 10);
}
function run_fact() {
%BenchTurbofan(fact, 10);
}
function run_prime() {
%BenchTurbofan(is_prime, 10);
}
function run_eratosthenes() {
%BenchTurbofan(eratosthenes, 10);
}
// Registering tests
createSuite('Medium-Copy', 1, run_copy);
createSuite('Medium-Fact', 1, run_fact);
createSuite('Medium-Prime', 1, run_prime);
createSuite('Medium-Eratosthenes', 1, run_eratosthenes);
})();

View File

@ -0,0 +1,31 @@
// Copyright 2023 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.
d8.file.execute('../base.js');
d8.file.execute('small.js');
d8.file.execute('medium.js');
d8.file.execute('large.js');
var success = true;
function PrintResult(name, result) {
// Multiplying results by 1000000 to have larger numbers (otherwise it's going
// to be a lot of small numbers like 0.00586).
print(name + '-Compile(Score): ' + result * 1000000);
}
function PrintStep(name) {}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });

View File

@ -0,0 +1,61 @@
// Copyright 2023 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.
(() => {
let a = 2, b = 3;
let arr = [1, 2, 3, 4, 5];
function empty() {}
function constant() {
return 42;
}
function add() {
return a + b;
}
function load() {
return arr[2];
}
// Initializing feedback for each function
%PrepareFunctionForOptimization(empty);
empty();
%PrepareFunctionForOptimization(constant);
constant();
%PrepareFunctionForOptimization(add);
add();
a = 4; b = 4;
add();
%PrepareFunctionForOptimization(load);
load();
arr[2] = 17;
load();
// Creating runners
function run_empty() {
%BenchTurbofan(empty, 100);
}
function run_constant() {
%BenchTurbofan(constant, 100);
}
function run_add() {
%BenchTurbofan(add, 100);
}
function run_load() {
%BenchTurbofan(load, 100);
}
// Registering tests
createSuite('Small-Empty', 1, run_empty);
createSuite('Small-Constant', 1, run_constant);
createSuite('Small-Add', 1, run_add);
createSuite('Small-Load', 1, run_load);
})();

View File

@ -0,0 +1,210 @@
// 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.
new BenchmarkSuite('DataViewTest-DataView-BigEndian', [1000], [
new Benchmark('DataViewTest-DataView-BigEndian', false, false, 0, doTestDataViewBigEndian),
]);
new BenchmarkSuite('DataViewTest-DataView-LittleEndian', [1000], [
new Benchmark('DataViewTest-DataView-LittleEndian', false, false, 0, doTestDataViewLittleEndian),
]);
new BenchmarkSuite('DataViewTest-DataView-Floats', [1000], [
new Benchmark('DataViewTest-DataView-Floats', false, false, 0, doTestDataViewFloats),
]);
new BenchmarkSuite('DataViewTest-TypedArray-BigEndian', [1000], [
new Benchmark('DataViewTest-TypedArray-BigEndian', false, false, 0, doTestTypedArrayBigEndian),
]);
new BenchmarkSuite('DataViewTest-TypedArray-LittleEndian', [1000], [
new Benchmark('DataViewTest-TypedArray-LittleEndian', false, false, 0, doTestTypedArrayLittleEndian),
]);
new BenchmarkSuite('DataViewTest-TypedArray-Floats', [1000], [
new Benchmark('DataViewTest-TypedArray-Floats', false, false, 0, doTestTypedArrayFloats),
]);
function doTestDataViewBigEndian() {
doIterations(false, true);
}
function doTestDataViewLittleEndian() {
doIterations(true, true);
}
function doTestTypedArrayBigEndian() {
doIterations(false, false);
}
function doTestTypedArrayLittleEndian() {
doIterations(true, false);
}
function doTestDataViewFloats() {
doFloatIterations(true);
}
function doTestTypedArrayFloats() {
doFloatIterations(false);
}
function doIterations(littleEndian, dataView) {
var buffer = makeBuffer(1000, littleEndian);
var iterations = 10;
if (dataView) {
for (var i = 0; i < iterations; i++)
doOneIterationDV(buffer, littleEndian);
} else {
for (var i = 0; i < iterations; i++)
doOneIterationJS(buffer, littleEndian);
}
}
function makeBuffer(size, littleEndian) {
var buffer = new ArrayBuffer(size * 14);
var view = new DataView(buffer);
for (var i = 0; i < size; ++i) {
view.setInt8(i * 14, i);
view.setUint8(i * 14 + 1, i);
view.setInt16(i * 14 + 2, i * i, littleEndian);
view.setUint16(i * 14 + 4, i * i, littleEndian);
view.setInt32(i * 14 + 6, i * i * i, littleEndian);
view.setUint32(i * 14 + 10, i * i * i, littleEndian);
}
return buffer;
}
function doOneIterationDV(buffer, littleEndian) {
var xor = 0;
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 14) {
xor ^= view.getInt8(i);
xor ^= view.getUint8(i + 1);
xor ^= view.getInt16(i + 2, littleEndian);
xor ^= view.getUint16(i + 4, littleEndian);
xor ^= view.getInt32(i + 6, littleEndian);
xor ^= view.getUint32(i + 10, littleEndian);
}
}
function doOneIterationJS(buffer, littleEndian) {
var xor = 0;
var reader;
if (littleEndian) {
reader = new LittleEndian(buffer);
} else {
reader = new BigEndian(buffer);
}
for (var i = 0; i < buffer.byteLength; i += 14) {
xor ^= reader.getInt8(i);
xor ^= reader.getUint8(i + 1);
xor ^= reader.getInt16(i + 2);
xor ^= reader.getUint16(i + 4);
xor ^= reader.getInt32(i + 6);
xor ^= reader.getUint32(i + 10);
}
}
function doFloatIterations(dataView) {
var buffer = makeFloatBuffer(1000);
var iterations = 10;
if (dataView) {
for (var i = 0; i < iterations; i++)
doOneFloatIterationDV(buffer);
} else {
for (var i = 0; i < iterations; i++)
doOneFloatIterationJS(buffer);
}
}
function makeFloatBuffer(size) {
var buffer = new ArrayBuffer(size * 16);
var view = new DataView(buffer);
for (var i = 0; i < size; i++) {
view.setFloat64(i * 16, Math.log10(i + 1));
view.setFloat32(i * 16 + 8, Math.sqrt(i));
view.setFloat32(i * 16 + 12, Math.cos(i));
}
return buffer;
}
function doOneFloatIterationDV(buffer) {
var sum = 0;
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 16) {
sum += view.getFloat64(i);
sum += view.getFloat32(i + 8);
sum += view.getFloat32(i + 12);
}
}
function doOneFloatIterationJS(buffer) {
var sum = 0;
var float32array = new Float32Array(buffer);
var float64array = new Float64Array(buffer);
for (var i = 0; i < buffer.byteLength; i += 16) {
sum += float64array[i/8];
sum += float32array[i/4 + 2];
sum += float32array[i/4 + 3];
}
}
function BigEndian(buffer, opt_byteOffset) {
this.uint8View_ = new Uint8Array(buffer, opt_byteOffset || 0);
this.int8View_ = new Int8Array(buffer, opt_byteOffset || 0);
}
BigEndian.prototype.getInt8 = function(byteOffset) {
return this.int8View_[byteOffset];
};
BigEndian.prototype.getUint8 = function(byteOffset) {
return this.uint8View_[byteOffset];
};
BigEndian.prototype.getInt16 = function(byteOffset) {
return this.uint8View_[byteOffset + 1] | (this.int8View_[byteOffset] << 8);
};
BigEndian.prototype.getUint16 = function(byteOffset) {
return this.uint8View_[byteOffset + 1] | (this.uint8View_[byteOffset] << 8);
};
BigEndian.prototype.getInt32 = function(byteOffset) {
return this.uint8View_[byteOffset + 3] |
(this.uint8View_[byteOffset + 2] << 8) |
(this.uint8View_[byteOffset + 1] << 16) |
(this.int8View_[byteOffset] << 24);
};
BigEndian.prototype.getUint32 = function(byteOffset) {
return this.uint8View_[byteOffset + 3] +
(this.uint8View_[byteOffset + 2] << 8) +
(this.uint8View_[byteOffset + 1] << 16) +
(this.uint8View_[byteOffset] * (1 << 24));
};
function LittleEndian(buffer, opt_byteOffset) {
this.uint8View_ = new Uint8Array(buffer, opt_byteOffset || 0);
this.int8View_ = new Int8Array(buffer, opt_byteOffset || 0);
}
LittleEndian.prototype.getInt8 = function(byteOffset) {
return this.int8View_[byteOffset];
};
LittleEndian.prototype.getUint8 = function(byteOffset) {
return this.uint8View_[byteOffset];
};
LittleEndian.prototype.getInt16 = function(byteOffset) {
return this.uint8View_[byteOffset] | (this.int8View_[byteOffset + 1] << 8);
};
LittleEndian.prototype.getUint16 = function(byteOffset) {
return this.uint8View_[byteOffset] | (this.uint8View_[byteOffset + 1] << 8);
};
LittleEndian.prototype.getInt32 = function(byteOffset) {
return this.uint8View_[byteOffset] |
(this.uint8View_[byteOffset + 1] << 8) |
(this.uint8View_[byteOffset + 2] << 16) |
(this.int8View_[byteOffset + 3] << 24);
};
LittleEndian.prototype.getUint32 = function(byteOffset) {
return this.uint8View_[byteOffset] +
(this.uint8View_[byteOffset + 1] << 8) +
(this.uint8View_[byteOffset + 2] << 16) +
(this.uint8View_[byteOffset + 3] * (1 << 24));
};

View File

@ -0,0 +1,24 @@
// Copyright 2014 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.
d8.file.execute('../base.js');
d8.file.execute('dataviewtest.js');
var success = true;
function PrintResult(name, result) {
print(`DataView-${name}(Score): ${result}`);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

20
deps/v8/test/js-perf-test/Dates/run.js vendored Normal file
View File

@ -0,0 +1,20 @@
// 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.
d8.file.execute('../base.js');
d8.file.execute('toLocaleString.js');
function PrintResult(name, result) {
console.log(name);
console.log(name + '-Dates(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,20 @@
// 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.
function DateToLocaleDateString() {
let d = new Date();
d.toLocaleDateString()
}
createSuite('toLocaleDateString', 100000, DateToLocaleDateString, ()=>{});
function DateToLocaleString() {
let d = new Date();
d.toLocaleString()
}
createSuite('toLocaleString', 100000, DateToLocaleString, ()=>{});
function DateToLocaleTimeString() {
let d = new Date();
d.toLocaleTimeString()
}
createSuite('toLocaleTimeString', 100000, DateToLocaleTimeString, ()=>{});

View File

@ -0,0 +1,26 @@
// Copyright 2015 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.
d8.file.execute('../base.js');
d8.file.execute('try-catch.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Exceptions(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,110 @@
// Copyright 2015 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.
new BenchmarkSuite('Try-Catch', [1000], [
new Benchmark('OnSuccess', false, false, 0,
OnSuccess, OnSuccessSetup,
OnSuccessTearDown),
new Benchmark('OnException', false, false, 0,
OnException, OnExceptionSetup,
OnExceptionTearDown),
new Benchmark('OnSuccessFinallyOnly', false, false, 0,
OnSuccessFinallyOnly, OnSuccessFinallyOnlySetup,
OnSuccessFinallyOnlyTearDown),
new Benchmark('WithFinallyOnException', false, false, 0,
WithFinallyOnException, WithFinallyOnExceptionSetup,
WithFinallyOnExceptionTearDown)
]);
var a;
var b;
var c;
// ----------------------------------------------------------------------------
function OnSuccessSetup() {
a = 4;
b = 6;
c = 0;
}
function OnSuccess() {
try {
c = a + b;
}
catch (e) {
c++;
}
}
function OnSuccessTearDown() {
return c === 10;
}
// ----------------------------------------------------------------------------
function OnExceptionSetup() {
a = 4;
b = 6;
c = 0;
}
function OnException() {
try {
throw 'Test exception';
}
catch (e) {
c = a + b;
}
}
function OnExceptionTearDown() {
return c === 10;
}
// ----------------------------------------------------------------------------
function OnSuccessFinallyOnlySetup() {
a = 4;
b = 6;
c = 0;
}
function OnSuccessFinallyOnly() {
try {
c = a + b;
}
finally {
c++;
}
}
function OnSuccessFinallyOnlyTearDown() {
return c === 11;
}
// ----------------------------------------------------------------------------
function WithFinallyOnExceptionSetup() {
a = 4;
b = 6;
c = 0;
}
function WithFinallyOnException() {
try {
throw 'Test exception';
}
catch (e) {
c = a + b;
}
finally {
c++;
}
}
function WithFinallyOnExceptionTearDown() {
return c === 11;
}
// ----------------------------------------------------------------------------

View File

@ -0,0 +1,90 @@
// Copyright 2017 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.
// Logical Expressions
AddTest('Or-Value', '||', false);
AddTest('Or-Test', '||', true);
AddTest('And-Value', '&&', false);
AddTest('And-Test', '&&', true);
AddTest('Comma-Value', ',', false);
AddTest('Comma-Test', ',', true);
AddTest('Comma-Test', ',', true);
// Compare Expressions
AddTest('Equals-Value', '==', false);
AddTest('Equals-Test', '==', true);
AddTest('StrictEquals-Value', '===', false);
AddTest('StrictEquals-Test', '===', true);
AddTest('GreaterThan-Value', '>', false);
AddTest('GreaterThan-Test', '>', true);
// Binary Expressions
AddTest('Add', '+');
AddTest('Sub', '-');
AddTest('BitwiseOr', '|');
AddTestCustomPrologue('StringConcat', '+', '"string" +');
AddTestCustomPrologue('TemplateString', '} ${', '`${', '}`');
function TestExpressionDepth(depth, expression, prologue, epilogue) {
var func = '(function f(a) {\n' + prologue;
for (var i = 0; i < depth; i++) {
func += 'a ' + expression;
}
func += 'a' + epilogue + '})();'
eval(func);
}
function RunTest(name, expression, prologue, epilogue) {
var low_depth = 0;
var high_depth = 1;
// Find the upper limit where depth breaks down.
try {
while (high_depth <= 65536) {
TestExpressionDepth(high_depth, expression, prologue, epilogue);
low_depth = high_depth;
high_depth *= 4;
}
// Looks like we can't get the depth to break down, just report
// the maximum depth tested.
print(name + '-ExpressionDepth(Score): ' + low_depth);
return;
} catch (e) {
if (!(e instanceof RangeError)) {
print(name + '-ExpressionDepth(Score): ERROR');
return;
}
}
// Binary search the actual limit.
while (low_depth + 1 < high_depth) {
var mid_depth = Math.round((low_depth + high_depth) / 2);
try {
TestExpressionDepth(mid_depth, expression, prologue, epilogue);
low_depth = mid_depth;
} catch (e) {
if (!(e instanceof RangeError)) {
print(name + '-ExpressionDepth(Score): ERROR');
return;
}
high_depth = mid_depth;
}
}
print(name + '-ExpressionDepth(Score): ' + low_depth);
}
function AddTest(name, expression, in_test) {
prologue = '';
epilogue = '';
if (in_test) {
prologue = 'if (';
epilogue = ') { return 1; }';
}
RunTest(name, expression, prologue, epilogue);
}
function AddTestCustomPrologue(name, expression, prologue, epilogue='') {
RunTest(name, expression, prologue, epilogue);
}

View File

@ -0,0 +1,42 @@
// Copyright 2017 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.
new BenchmarkSuite('Let-Standard', [1000], [
new Benchmark('Let-Standard', false, false, 0, LetLoop),
]);
new BenchmarkSuite('Var-Standard', [1000], [
new Benchmark('Var-Standard', false, false, 0, VarLoop),
]);
var x = [-1, 1, 4];
var y = [-11, -1, 1, 2, 3, 4, 5, 6, 20, 44, 87, 99, 100];
function LetLoop() {
"use strict";
const ret = [];
for (let i = 0; i < x.length; i++) {
for (let z = 0; z < y.length; z++) {
if (x[i] == y[z]) {
ret.push(x[i]);
break;
}
}
}
return ret;
}
function VarLoop() {
"use strict";
const ret = [];
for (var i = 0; i < x.length; i++) {
for (var z = 0; z < y.length; z++) {
if (x[i] == y[z]) {
ret.push(x[i]);
break;
}
}
}
return ret;
}

View File

@ -0,0 +1,25 @@
// Copyright 2017 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.
d8.file.execute('../base.js');
d8.file.execute('for_loop.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ForLoop(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,131 @@
// Copyright 2016 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.
new BenchmarkSuite('Generators', [1000], [
new Benchmark('Basic', false, false, 0, Basic),
new Benchmark('Loop', false, false, 0, Loop),
new Benchmark('Input', false, false, 0, Input),
new Benchmark('YieldStar', false, false, 0, YieldStar),
]);
// ----------------------------------------------------------------------------
// Benchmark: Basic
// ----------------------------------------------------------------------------
function* five() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
function Basic() {
let g = five();
let sum = 0;
sum += g.next().value;
sum += g.next().value;
sum += g.next().value;
sum += g.next().value;
sum += g.next().value;
if (sum != 15 || !g.next().done) throw "wrong";
}
// ----------------------------------------------------------------------------
// Benchmark: Loop
// ----------------------------------------------------------------------------
function* fibonacci() {
let x = 0;
let y = 1;
yield x;
while (true) {
yield y;
let tmp = x;
x = y;
y += tmp;
}
}
function Loop() {
let n = 0;
let x;
for (x of fibonacci()) {
if (++n === 42) break;
}
if (x != 165580141) throw "wrong";
}
// ----------------------------------------------------------------------------
// Benchmark: Input
// ----------------------------------------------------------------------------
function* multiples(x) {
let skip = 2;
let next = 0;
while (true) {
if (skip === 0) {
skip = yield next;
} else {
skip--;
}
next += x;
}
}
function Input() {
let g = multiples(3);
results = [g.next(2), g.next(0), g.next(5), g.next(10)];
if (results.slice(-1)[0].value != 60) throw "wrong";
}
// ----------------------------------------------------------------------------
// Benchmark: YieldStar
// ----------------------------------------------------------------------------
function* infix(node) {
if (node) {
yield* infix(node.left);
yield node.label;
yield* infix(node.right);
}
}
class Node {
constructor(label, left, right) {
this.label = label;
this.left = left;
this.right = right;
}
}
function YieldStar() {
let tree = new Node(1,
new Node(2,
new Node(3,
new Node(4,
new Node(16,
new Node(5,
new Node(23,
new Node(0),
new Node(17)),
new Node(44, new Node(20)))),
new Node(7,
undefined,
new Node(23,
new Node(0),
new Node(41, undefined, new Node(11))))),
new Node(8)),
new Node(5)),
new Node(6, undefined, new Node(7)));
let labels = [...(infix(tree))];
// 0,23,17,5,20,44,16,4,7,0,23,41,11,3,8,2,5,1,6,7
if (labels[0] != 0) throw "wrong";
}

View File

@ -0,0 +1,26 @@
// Copyright 2016 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.
d8.file.execute('../base.js');
d8.file.execute('generators.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Generators(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,85 @@
{
"name": "GetOwnPropertyDescriptorTests",
"run_count": 5,
"run_count_android_arm": 3,
"run_count_android_arm64": 3,
"timeout": 300,
"units": "score",
"total": true,
"owners": ["caitp"],
"resources": ["base.js"],
"tests": [
{
"name": "GetOwnPropertyDescriptor",
"path": ["."],
"main": "run.js",
"flags": [""],
"resources": [
"get-own-property-descriptor.js"
],
"results_regexp": "^%s\\-GetOwnPropertyDescriptor\\(Score\\): (.+)$",
"tests": [
{"name": "ObjectGetOwnPropertyDescriptor--object--INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--object--DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--object--NE-INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--object--NE-DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--object--el"},
{"name": "ObjectGetOwnPropertyDescriptor--object--NE-el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--NE-INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--NE-DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-no-trap--NE-el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--NE-INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--NE-DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-reflect--NE-el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-INTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-DEINTERN-prop"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--el"},
{"name": "ObjectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-el"},
{"name": "ReflectGetOwnPropertyDescriptor--object--INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--object--DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--object--NE-INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--object--NE-DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--object--el"},
{"name": "ReflectGetOwnPropertyDescriptor--object--NE-el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--NE-INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--NE-DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-no-trap--NE-el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--NE-INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--NE-DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-reflect--NE-el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-no-trap--NE-el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-INTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-DEINTERN-prop"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--el"},
{"name": "ReflectGetOwnPropertyDescriptor--proxy-proxy-reflect--NE-el"}
]
}
]
}

View File

@ -0,0 +1,280 @@
// Copyright 2022 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.
function ObjectWithKeys(count, keyOffset = 0, keyGen) {
var body = "";
for (var i = 0; i < count; i++) {
var key = keyGen(i + keyOffset);
if (typeof key === "string") {
body += `this.${key} = 0\n`;
} else {
body += `this[${key}] = 0\n`;
}
}
var f = new Function(body);
return new f();
}
function ObjectWithProperties(count, keyOffset) {
return ObjectWithKeys(count, keyOffset, (key) => "key" + key );
}
function ObjectWithElements(count, keyOffset) {
return ObjectWithKeys(count, keyOffset, (key) => key );
}
function ObjectWithMixedKeys(count, keyOffset) {
return ObjectWithKeys(count, keyOffset, (key) => {
if (key % 2 == 0) return (key / 2);
return "key" + ((key - 1) / 2);
});
}
// Create an object with 0 prototypes each having #keys properties
// generated by given keyGen.
function ObjectWithOwnKeys(depth, keys,
keyGen = ObjectWithProperties) {
var o = keyGen(keys);
var current = o;
var keyOffset = 0;
for (var i = 0; i < 1; i++) {
keyOffset += keys;
current.__proto__ = keyGen(keys, keyOffset);
}
return o;
}
function HoleyIntArray(size) {
var array = new Array(size);
for (var i = 0; i < size; i += 3) {
array[i] = i;
}
return array
}
function IntArray(size) {
var array = new Array(size);
for (var i = 0; i < size; i++) {
array[i] = i;
}
return array;
}
// Switch object's properties and elements to dictionary mode.
function MakeDictionaryMode(obj) {
obj.foo = 0;
obj.bar = 0;
// Delete the second-to-last property first to force normalization.
delete obj.foo;
delete obj.bar;
obj[1e9] = 0;
return obj;
}
function Internalize(s) {
return Object.keys({[s]:0})[0];
}
function Deinternalize(s) {
return [...s].join("");
}
// ============================================================================
const QUERY_INTERNALIZED_PROP = "INTERN-prop";
const QUERY_DEINTERNALIZED_PROP = "DEINTERN-prop";
const QUERY_NON_EXISTING_INTERNALIZED_PROP = "NE-INTERN-prop";
const QUERY_NON_EXISTING_DEINTERNALIZED_PROP = "NE-DEINTERN-prop";
const QUERY_ELEMENT = "el";
const QUERY_NON_EXISTING_ELEMENT = "NE-el";
const OBJ_MODE_FAST = "fast";
const OBJ_MODE_SLOW = "slow";
var TestQueries = [
QUERY_INTERNALIZED_PROP,
QUERY_DEINTERNALIZED_PROP,
QUERY_NON_EXISTING_INTERNALIZED_PROP,
QUERY_NON_EXISTING_DEINTERNALIZED_PROP,
QUERY_ELEMENT,
QUERY_NON_EXISTING_ELEMENT,
];
const QUERIES_PER_OBJECT_NUMBER = 10;
// Leave only every "count"th keys.
function FilterKeys(keys, count) {
var len = keys.length;
if (len < count) throw new Error("Keys array is too short: " + len);
var step = len / count;
if (step == 0) throw new Error("Bad count specified: " + count);
return keys.filter((element, index) => index % step == 0);
}
function MakeKeyQueries(keys, query_kind) {
var properties = keys.filter((element) => isNaN(Number(element)));
var elements = keys.filter((element) => !isNaN(Number(element)));
properties = FilterKeys(properties, QUERIES_PER_OBJECT_NUMBER);
elements = FilterKeys(elements, QUERIES_PER_OBJECT_NUMBER);
switch (query_kind) {
case QUERY_INTERNALIZED_PROP:
return properties;
case QUERY_DEINTERNALIZED_PROP:
return properties.map(Deinternalize);
case QUERY_NON_EXISTING_INTERNALIZED_PROP:
case QUERY_NON_EXISTING_DEINTERNALIZED_PROP:
var non_existing = [];
for (var i = 0; i < QUERIES_PER_OBJECT_NUMBER; i++) {
non_existing.push("non-existing" + i);
}
if (query_kind == QUERY_NON_EXISTING_INTERNALIZED_PROP) {
return non_existing.map(Internalize);
} else {
return non_existing.map(Deinternalize);
}
case QUERY_ELEMENT:
return elements.map(Number);
case QUERY_NON_EXISTING_ELEMENT:
var non_existing = [];
for (var i = 0; i < QUERIES_PER_OBJECT_NUMBER; i++) {
non_existing.push(1200 + 100*i);
}
return non_existing;
default:
throw new Error("Bad query_kind: " + query_kind);
}
}
var TestData = [];
[OBJ_MODE_FAST, OBJ_MODE_SLOW].forEach((obj_mode) => {
var name = `${obj_mode}-obj`;
var objects = [];
[10, 50, 100, 200, 500].forEach((prop_count) => {
// Create object with prop_count properties and prop_count elements.
obj = ObjectWithOwnKeys(5, prop_count * 2, ObjectWithMixedKeys);
if (obj_mode == OBJ_MODE_SLOW) {
obj = MakeDictionaryMode(obj);
}
objects.push(obj);
});
TestData.push({name, objects});
});
// ============================================================================
function CreateTestFunction(testMethod, object, keys) {
// Force a new function for each test-object to avoid side-effects due to ICs.
var text = `
// random comment ${Math.random()}
let results = [];
for (var key in keys) {
results.push(${testMethod}(object, key));
}
return results;`;
var func = new Function("object", "keys", text);
return () => func(object, keys);
}
function CombineTestFunctions(tests) {
return () => {
for (var i = 0; i < tests.length; i++ ) {
let results = tests[i]();
results.push(1);
globalThis.results = results;
}
};
}
var TestMethods = {
"ObjectGetOwnPropertyDescriptor": "Object.getOwnPropertyDescriptor",
"ReflectGetOwnPropertyDescriptor": "Reflect.getOwnPropertyDescriptor",
};
var TestTargets = {
"object": {
target(object) {
return object;
}
},
"proxy-no-trap": {
target(object) {
return new Proxy(object, {});
},
},
"proxy-reflect": {
target(object) {
return new Proxy(object, {
getOwnPropertyDescriptor(target, propertyKey) {
return Reflect.getOwnPropertyDescriptor(target, propertyKey);
}
});
}
},
"proxy-proxy-no-trap": {
target(object) {
let proxy = this["proxy-no-trap"].target(object);
return new Proxy(proxy, {});
}
},
"proxy-proxy-reflect": {
target(object) {
let proxy = this["proxy-no-trap"].target(object);
return new Proxy(object, {
getOwnPropertyDescriptor(target, propertyKey) {
return Reflect.getOwnPropertyDescriptor(target, propertyKey);
}
});
}
}
};
// ============================================================================
// Create the benchmark suites. We create a suite for each pair of the test
// functions above and query kind. Each suite contains benchmarks for each
// object type.
var Benchmarks = [];
for (var [test_method_name, test_method_entry] of Object.entries(TestMethods)) {
for (var [test_target_name, test_target] of Object.entries(TestTargets)) {
for (var query_kind of TestQueries) {
var benchmarks = [];
var suit_name = `${test_method_name}--${test_target_name}--${query_kind}`;
for (var test_data of TestData) {
var name = `${suit_name}--${test_data.name}`;
var tests = [];
for (var object of test_data.objects) {
var keys = Object.getOwnPropertyNames(object);
keys = MakeKeyQueries(keys, query_kind);
var test = CreateTestFunction(test_method_entry, object, keys);
tests.push(test);
}
var run_function = CombineTestFunctions(tests);
var benchmark = new Benchmark(name, false, false, 0, run_function);
benchmarks.push(benchmark);
}
Benchmarks.push(new BenchmarkSuite(suit_name, [100], benchmarks));
}
}
}
// ============================================================================

Some files were not shown because too many files have changed in this diff Show More