2018-02-05 15:53:36 +00:00
|
|
|
// 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.
|
|
|
|
(() => {
|
|
|
|
|
2018-05-24 14:26:15 +00:00
|
|
|
createSuite('MixedFrom', 1000, MixedFrom, MixedFromSetup);
|
2018-11-02 10:54:23 +00:00
|
|
|
createSuite(
|
|
|
|
'MixedCowNoMapFrom', 1000, MixedCowNoMapFrom, MixedCowNoMapFromSetup);
|
|
|
|
createSuite('MixedNonCowNoMapFrom', 1000, MixedNonCowNoMapFrom,
|
|
|
|
MixedNonCowNoMapFromSetup);
|
2018-05-24 14:26:15 +00:00
|
|
|
createSuite('SmiFrom', 1000, SmiFrom, SmiFromSetup);
|
|
|
|
createSuite('SmallSmiFrom', 1000, SmallSmiFrom, SmallSmiFromSetup);
|
2018-11-02 10:54:23 +00:00
|
|
|
createSuite('SmiCowNoMapFrom', 1000, SmiCowNoMapFrom, SmiCowNoMapFromSetup);
|
|
|
|
createSuite(
|
|
|
|
'SmiNonCowNoMapFrom', 1000, SmiNonCowNoMapFrom, SmiNonCowNoMapFromSetup);
|
2018-05-24 14:26:15 +00:00
|
|
|
createSuite(
|
|
|
|
'SmiNoIteratorFrom', 1000, SmiNoIteratorFrom, SmiNoIteratorFromSetup);
|
|
|
|
createSuite(
|
|
|
|
'TransplantedFrom', 1000, TransplantedFrom, TransplantedFromSetup);
|
|
|
|
createSuite('DoubleFrom', 1000, DoubleFrom, DoubleFromSetup);
|
2018-10-24 13:33:02 +00:00
|
|
|
createSuite('DoubleNoMapFrom', 1000, DoubleNoMapFrom, DoubleNoMapFromSetup);
|
2018-05-24 14:26:15 +00:00
|
|
|
createSuite('StringFrom', 1000, StringFrom, StringFromSetup);
|
2018-11-02 10:54:23 +00:00
|
|
|
createSuite(
|
|
|
|
'StringCowNoMapFrom', 1000, StringCowNoMapFrom, StringCowNoMapFromSetup);
|
|
|
|
createSuite('StringNonCowNoMapFrom', 1000, StringNonCowNoMapFrom,
|
|
|
|
StringNonCowNoMapFromSetup);
|
2018-05-24 14:26:15 +00:00
|
|
|
|
|
|
|
function ArrayLike() {}
|
|
|
|
ArrayLike.from = Array.from;
|
|
|
|
|
|
|
|
var arg
|
|
|
|
var result;
|
|
|
|
var func
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
// 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 = [
|
2018-05-24 14:26:15 +00:00
|
|
|
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,
|
|
|
|
];
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
// 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.
|
2018-05-24 14:26:15 +00:00
|
|
|
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,
|
|
|
|
];
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
// This creates a COW array of objects.
|
|
|
|
var string_array_Cow = [
|
2018-05-24 14:26:15 +00:00
|
|
|
'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',
|
|
|
|
];
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
// 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 = [
|
2018-05-24 14:26:15 +00:00
|
|
|
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',
|
|
|
|
];
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
// This creates a non-COW array.
|
|
|
|
var mixed_array = Array.from(mixed_array_Cow);
|
|
|
|
mixed_array[0] = 1;
|
|
|
|
|
2018-05-24 14:26:15 +00:00
|
|
|
// Although these functions have the same code, they are separated for
|
|
|
|
// clean IC feedback.
|
|
|
|
function SmallSmiFrom() {
|
|
|
|
result = Array.from(arg, func);
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function SmiCowNoMapFrom() {
|
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SmiNonCowNoMapFrom() {
|
2018-05-24 14:26:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:33:02 +00:00
|
|
|
function DoubleNoMapFrom() {
|
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
2018-05-24 14:26:15 +00:00
|
|
|
function StringFrom() {
|
|
|
|
result = Array.from(arg, func);
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function StringCowNoMapFrom() {
|
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function StringNonCowNoMapFrom() {
|
2018-05-24 14:26:15 +00:00
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function MixedFrom() {
|
|
|
|
result = Array.from(arg, func);
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function MixedCowNoMapFrom() {
|
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function MixedNonCowNoMapFrom() {
|
2018-10-24 13:33:02 +00:00
|
|
|
result = Array.from(arg);
|
|
|
|
}
|
|
|
|
|
2018-05-24 14:26:15 +00:00
|
|
|
function SmallSmiFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
|
|
|
arg = [1, 2, 3];
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function SmiCowNoMapFromSetup() {
|
|
|
|
func = undefined;
|
|
|
|
arg = smi_array_Cow;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SmiNonCowNoMapFromSetup() {
|
2018-05-24 14:26:15 +00:00
|
|
|
func = undefined;
|
|
|
|
arg = smi_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SmiFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
2018-11-02 10:54:23 +00:00
|
|
|
arg = smi_array_Cow;
|
2018-05-24 14:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SmiNoIteratorFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
2018-11-02 10:54:23 +00:00
|
|
|
array = smi_array_Cow;
|
2018-06-05 09:49:59 +00:00
|
|
|
arg = {length: array.length};
|
|
|
|
Object.assign(arg, array);
|
2018-05-24 14:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TransplantedFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
2018-11-02 10:54:23 +00:00
|
|
|
arg = smi_array_Cow;
|
2018-05-24 14:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DoubleFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
|
|
|
arg = double_array;
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:33:02 +00:00
|
|
|
function DoubleNoMapFromSetup() {
|
|
|
|
func = undefined;
|
|
|
|
arg = double_array;
|
|
|
|
}
|
|
|
|
|
2018-05-24 14:26:15 +00:00
|
|
|
function StringFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
2018-11-02 10:54:23 +00:00
|
|
|
arg = string_array_Cow;
|
2018-05-24 14:26:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function StringCowNoMapFromSetup() {
|
|
|
|
func = undefined;
|
|
|
|
arg = string_array_Cow;
|
|
|
|
}
|
|
|
|
|
|
|
|
function StringNonCowNoMapFromSetup() {
|
2018-05-24 14:26:15 +00:00
|
|
|
func = undefined;
|
|
|
|
arg = string_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
function MixedFromSetup() {
|
|
|
|
func = (v, i) => v + i;
|
2018-11-02 10:54:23 +00:00
|
|
|
arg = mixed_array_Cow;
|
|
|
|
}
|
|
|
|
|
|
|
|
function MixedCowNoMapFromSetup() {
|
|
|
|
func = undefined;
|
|
|
|
arg = mixed_array_Cow;
|
2018-05-24 14:26:15 +00:00
|
|
|
}
|
2018-02-05 15:53:36 +00:00
|
|
|
|
2018-11-02 10:54:23 +00:00
|
|
|
function MixedNonCowNoMapFromSetup() {
|
2018-10-24 13:33:02 +00:00
|
|
|
func = undefined;
|
|
|
|
arg = mixed_array;
|
|
|
|
}
|
2018-02-05 15:53:36 +00:00
|
|
|
})();
|