2017-03-21 08:56:56 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
load('../base.js');
|
|
|
|
|
2018-01-15 15:58:36 +00:00
|
|
|
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;
|
|
|
|
|
2018-08-09 10:59:51 +00:00
|
|
|
// newClosure is a handy function to get a fresh
|
2018-01-15 15:58:36 +00:00
|
|
|
// closure unpolluted by IC feedback for a 2nd-order array builtin
|
|
|
|
// test.
|
2018-08-09 10:59:51 +00:00
|
|
|
function newClosure(name, generic = false) {
|
2018-01-15 15:58:36 +00:00
|
|
|
if (generic) {
|
|
|
|
return new Function(
|
|
|
|
`result = Array.prototype.${name}.call(array, func, this_arg);`);
|
|
|
|
}
|
|
|
|
return new Function(`result = array.${name}(func, this_arg);`);
|
|
|
|
}
|
|
|
|
|
2018-08-09 10:59:51 +00:00
|
|
|
function MakeHoley(array) {
|
|
|
|
for (let i =0; i < array.length; i+=2) {
|
|
|
|
delete array[i];
|
|
|
|
}
|
|
|
|
assert(%HasHoleyElements(array));
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:58:36 +00:00
|
|
|
function SmiSetup() {
|
|
|
|
array = Array.from({ length: array_size }, (_, i) => i);
|
2018-08-09 10:59:51 +00:00
|
|
|
assert(%HasSmiElements(array));
|
|
|
|
}
|
|
|
|
|
|
|
|
function HoleySmiSetup() {
|
|
|
|
SmiSetup();
|
|
|
|
MakeHoley(array);
|
|
|
|
assert(%HasSmiElements(array));
|
2018-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DoubleSetup() {
|
|
|
|
array = Array.from({ length: array_size }, (_, i) => i + 0.5);
|
2018-08-09 10:59:51 +00:00
|
|
|
assert(%HasDoubleElements(array));
|
|
|
|
}
|
|
|
|
|
|
|
|
function HoleyDoubleSetup() {
|
|
|
|
DoubleSetup();
|
|
|
|
MakeHoley(array);
|
|
|
|
assert(%HasDoubleElements(array));
|
2018-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function FastSetup() {
|
|
|
|
array = Array.from({ length: array_size }, (_, i) => `value ${i}`);
|
2018-08-13 13:33:35 +00:00
|
|
|
assert(%HasObjectElements(array));
|
2018-08-09 10:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function HoleyFastSetup() {
|
|
|
|
FastSetup();
|
|
|
|
MakeHoley(array);
|
2018-08-13 13:33:35 +00:00
|
|
|
assert(%HasObjectElements(array));
|
2018-08-09 10:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:33:35 +00:00
|
|
|
function DictionarySetup() {
|
2018-08-09 10:59:51 +00:00
|
|
|
array = [];
|
|
|
|
// Add a large index to force dictionary elements.
|
2018-09-06 10:59:49 +00:00
|
|
|
array[2**30] = 10;
|
|
|
|
// Spread out {array_size} elements.
|
|
|
|
for (var i = 0; i < array_size-1; i++) {
|
|
|
|
array[i*101] = i;
|
2018-08-09 10:59:51 +00:00
|
|
|
}
|
|
|
|
assert(%HasDictionaryElements(array));
|
2018-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ObjectSetup() {
|
|
|
|
array = { length: array_size };
|
|
|
|
for (var i = 0; i < array_size; i++) {
|
|
|
|
array[i] = i;
|
|
|
|
}
|
2018-08-09 10:59:51 +00:00
|
|
|
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,
|
2018-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DefineHigherOrderTests(tests) {
|
|
|
|
let i = 0;
|
|
|
|
while (i < tests.length) {
|
2018-08-09 10:59:51 +00:00
|
|
|
const [name, testFunc, setupFunc, callback] = tests[i++];
|
2018-01-15 15:58:36 +00:00
|
|
|
|
|
|
|
let setupFuncWrapper = () => {
|
|
|
|
func = callback;
|
|
|
|
this_arg = undefined;
|
|
|
|
setupFunc();
|
|
|
|
};
|
2018-05-24 14:26:15 +00:00
|
|
|
createSuite(name, 1000, testFunc, setupFuncWrapper);
|
2018-01-15 15:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Higher-order Array builtins.
|
2017-03-21 08:56:56 +00:00
|
|
|
load('filter.js');
|
2017-03-24 17:39:34 +00:00
|
|
|
load('map.js');
|
2017-07-04 08:33:39 +00:00
|
|
|
load('every.js');
|
|
|
|
load('some.js');
|
2018-01-16 13:22:10 +00:00
|
|
|
load('for-each.js');
|
2017-07-04 08:33:39 +00:00
|
|
|
load('reduce.js');
|
|
|
|
load('reduce-right.js');
|
2017-12-05 12:23:48 +00:00
|
|
|
load('find.js');
|
2017-12-06 13:55:06 +00:00
|
|
|
load('find-index.js');
|
2017-03-21 08:56:56 +00:00
|
|
|
|
2018-01-15 15:58:36 +00:00
|
|
|
// Other Array builtins.
|
2018-02-05 15:53:36 +00:00
|
|
|
load('from.js');
|
|
|
|
load('of.js');
|
2018-01-15 15:58:36 +00:00
|
|
|
load('join.js');
|
|
|
|
load('to-string.js');
|
2018-06-11 09:10:45 +00:00
|
|
|
load('slice.js');
|
2018-08-08 14:20:22 +00:00
|
|
|
load('copy-within.js');
|
2018-01-15 15:58:36 +00:00
|
|
|
|
2017-03-21 08:56:56 +00:00
|
|
|
var success = true;
|
|
|
|
|
|
|
|
function PrintResult(name, result) {
|
|
|
|
print(name + '-Array(Score): ' + result);
|
|
|
|
}
|
|
|
|
|
2017-03-24 17:39:34 +00:00
|
|
|
function PrintStep(name) {}
|
2017-03-21 08:56:56 +00:00
|
|
|
|
|
|
|
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 });
|