Commit d845d28e authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[js-perf-tests] Cleanup and more elements kind helpers

Bug: chromium:840785
Change-Id: I93f417084cc3ad3d1b906bdbef5dda14ead208c6
Reviewed-on: https://chromium-review.googlesource.com/1169044Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55082}
parent c2545cc9
......@@ -27,11 +27,11 @@ function OptUnreliableEvery() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"DoubleEvery", mc("every"), DoubleSetup, v => v > 0.0,
"SmiEvery", mc("every"), SmiSetup, v => v != 34343,
"FastEvery", mc("every"), FastSetup, v => v !== 'hi',
"OptFastEvery", OptFastEvery, FastSetup, v => true,
"OptUnreliableEvery", OptUnreliableEvery, FastSetup, v => true
['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]
]);
})();
......@@ -54,13 +54,19 @@ function OptUnreliableFilter() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"NaiveFilterReplacement", NaiveFilter, NaiveFilterSetup, v => true,
"DoubleFilter", mc("filter"), DoubleSetup, v => Math.floor(v) % 2 === 0,
"SmiFilter", mc("filter"), SmiSetup, v => v % 2 === 0,
"FastFilter", mc("filter"), FastSetup, (_, i) => i % 2 === 0,
"GenericFilter", mc("filter", true), ObjectSetup, (_, i) => i % 2 === 0,
"OptFastFilter", OptFastFilter, FastSetup, undefined,
"OptUnreliableFilter", OptUnreliableFilter, FastSetup, v => true
['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]
]);
})();
......@@ -51,13 +51,22 @@ function NaiveSetup() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"NaiveFindIndexReplacement", Naive, NaiveSetup, v => v === max_index,
"DoubleFindIndex", mc("findIndex"), DoubleSetup, v => v === max_index + 0.5,
"SmiFindIndex", mc("findIndex"), SmiSetup, v => v === max_index,
"FastFindIndex", mc("findIndex"), FastSetup, v => v === `value ${max_index}`,
"GenericFindIndex", mc("findIndex", true), ObjectSetup, v => v === max_index,
"OptFastFindIndex", OptFast, FastSetup, undefined,
"OptUnreliableFindIndex", OptUnreliable, FastSetup, v => v === max_index
['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 === `value ${max_index}`
],
[
'GenericFindIndex', newClosure('findIndex', true), ObjectSetup,
v => v === max_index
],
['OptFastFindIndex', OptFast, FastSetup, undefined],
['OptUnreliableFindIndex', OptUnreliable, FastSetup, v => v === max_index]
]);
})();
......@@ -51,13 +51,13 @@ function NaiveSetup() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"NaiveFindReplacement", Naive, NaiveSetup, v => v === max_index,
"DoubleFind", mc("find"), DoubleSetup, v => v === max_index + 0.5,
"SmiFind", mc("find"), SmiSetup, v => v === max_index,
"FastFind", mc("find"), FastSetup, v => v === `value ${max_index}`,
"GenericFind", mc("find", true), ObjectSetup, v => v === max_index,
"OptFastFind", OptFast, FastSetup, undefined,
"OptUnreliableFind", OptUnreliable, FastSetup, v => v === max_index
['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 === `value ${max_index}`],
['GenericFind', newClosure('find', true), ObjectSetup, v => v === max_index],
['OptFastFind', OptFast, FastSetup, undefined],
['OptUnreliableFind', OptUnreliable, FastSetup, v => v === max_index]
]);
})();
......@@ -50,13 +50,25 @@ function OptUnreliable() {
}
DefineHigherOrderTests([
"NaiveForEachReplacement", Naive, NaiveSetup, v => v === max_index,
"DoubleForEach", mc("forEach"), DoubleSetup, v => v === max_index + 0.5,
"SmiForEach", mc("forEach"), SmiSetup, v => v === max_index,
"FastForEach", mc("forEach"), FastSetup, v => v === `value ${max_index}`,
"GenericForEach", mc("forEach", true), ObjectSetup, v => v === max_index,
"OptFastForEach", OptFast, FastSetup, undefined,
"OptUnreliableForEach", OptUnreliable, FastSetup, v => v === `value ${max_index}`
['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 === `value ${max_index}`
],
[
'GenericForEach', newClosure('forEach', true), ObjectSetup,
v => v === max_index
],
['OptFastForEach', OptFast, FastSetup, undefined],
[
'OptUnreliableForEach', OptUnreliable, FastSetup,
v => v === `value ${max_index}`
]
]);
})();
......@@ -49,15 +49,15 @@ function OptUnreliableMap() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"NaiveMapReplacement", NaiveMap, NaiveMapSetup, v => v,
"SmiMap", mc("map"), SmiSetup, v => v,
"DoubleMap", mc("map"), DoubleSetup, v => v,
"FastMap", mc("map"), FastSetup, v => v,
"SmallSmiToDoubleMap", mc("map"), SmiSetup, v => v + 0.5,
"SmallSmiToFastMap", mc("map"), SmiSetup, v => "hi" + v,
"GenericMap", mc("map", true), ObjectSetup, v => v,
"OptFastMap", OptFastMap, FastSetup, undefined,
"OptUnreliableMap", OptUnreliableMap, FastSetup, v => v
['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]
]);
})();
......@@ -27,12 +27,22 @@ function OptUnreliableReduceRight() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"DoubleReduceRight", mc("reduceRight"), DoubleSetup, (p, v, i, o) => p + v,
"SmiReduceRight", mc("reduceRight"), SmiSetup, (p, v, i, a) => p + 1,
"FastReduceRight", mc("reduceRight"), FastSetup, (p, v, i, a) => p + v,
"OptFastReduceRight", OptFastReduceRight, FastSetup, undefined,
"OptUnreliableReduceRight", OptUnreliableReduceRight, FastSetup,
(p, v, i, a) => p + v
[
'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
]
]);
})();
......@@ -27,12 +27,13 @@ function OptUnreliableReduce() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"DoubleReduce", mc("reduce"), DoubleSetup, (p, v, i, o) => p + v,
"SmiReduce", mc("reduce"), SmiSetup, (p, v, i, a) => p + 1,
"FastReduce", mc("reduce"), FastSetup, (p, v, i, a) => p + v,
"OptFastReduce", OptFastReduce, FastSetup, undefined,
"OptUnreliableReduce", OptUnreliableReduce, FastSetup,
(p, v, i, a) => p = v
['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
]
]);
})();
......@@ -13,10 +13,10 @@ let result;
const array_size = 100;
const max_index = array_size - 1;
// mc stands for "Make Closure," it's a handy function to get a fresh
// newClosure is a handy function to get a fresh
// closure unpolluted by IC feedback for a 2nd-order array builtin
// test.
function mc(name, generic = false) {
function newClosure(name, generic = false) {
if (generic) {
return new Function(
`result = Array.prototype.${name}.call(array, func, this_arg);`);
......@@ -24,16 +24,55 @@ function mc(name, generic = false) {
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 = Array.from({ length: array_size }, (_, i) => i);
assert(%HasSmiElements(array));
}
function HoleySmiSetup() {
SmiSetup();
MakeHoley(array);
assert(%HasSmiElements(array));
}
function DoubleSetup() {
array = Array.from({ length: array_size }, (_, i) => i + 0.5);
assert(%HasDoubleElements(array));
}
function HoleyDoubleSetup() {
DoubleSetup();
MakeHoley(array);
assert(%HasDoubleElements(array));
}
function FastSetup() {
array = Array.from({ length: array_size }, (_, i) => `value ${i}`);
assert(%HasObjectElements(array);
}
function HoleyFastSetup() {
FastSetup();
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() {
......@@ -41,15 +80,25 @@ function ObjectSetup() {
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 = tests[i++];
const testFunc = tests[i++];
const setupFunc = tests[i++];
const callback = tests[i++];
const [name, testFunc, setupFunc, callback] = tests[i++];
let setupFuncWrapper = () => {
func = callback;
......
......@@ -27,11 +27,11 @@ function OptUnreliableSome() {
DefineHigherOrderTests([
// name, test function, setup function, user callback
"DoubleSome", mc("some"), DoubleSetup, v => v < 0.0,
"SmiSome", mc("some"), SmiSetup, v => v === 34343,
"FastSome", mc("some"), FastSetup, v => v === 'hi',
"OptFastSome", OptFastSome, FastSetup, undefined,
"OptUnreliableSome", OptUnreliableSome, FastSetup, v => v === 'hi'
['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']
]);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment