[js-perf-test] Add Collection constructor and double type microbenchmarks

- Add {Map/Set/WeakMap/WeakSet}-Constructor microbenchmarks
- Add {Map/Set}-Double microbenchmarks (testing heap number keys)

Bug: v8:6604
Change-Id: Icadd5c81bfb59a58a2a65e119663d3f22637165d
Reviewed-on: https://chromium-review.googlesource.com/773595
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49398}
This commit is contained in:
peterwmwong 2017-11-15 21:41:49 -06:00 committed by Commit Bot
parent 007203abd0
commit 0a66361d7c
6 changed files with 210 additions and 1 deletions

View File

@ -5,18 +5,44 @@
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

@ -24,6 +24,13 @@ var MapObjectBenchmark = new BenchmarkSuite('Map-Object', [1000], [
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),
@ -37,6 +44,13 @@ 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() {
@ -74,10 +88,24 @@ function MapSetupObject() {
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);
@ -119,6 +147,11 @@ function MapDeleteSmi() {
}
}
function MapConstructorString() {
map = new Map(keyValuePairs);
}
function MapSetString() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
@ -160,6 +193,11 @@ function MapDeleteString() {
}
}
function MapConstructorObject() {
map = new Map(keyValuePairs);
}
function MapSetObject() {
for (var i = 0; i < N; i++) {
map.set(keys[i], i);
@ -216,6 +254,52 @@ function MapDeleteObject() {
}
}
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) {

View File

@ -24,6 +24,13 @@ var SetObjectBenchmark = new BenchmarkSuite('Set-Object', [1000], [
]);
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),
]);
@ -34,6 +41,13 @@ var SetIterationBenchmark = new BenchmarkSuite('Set-Iterator', [1000], [
]);
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;
@ -73,11 +87,28 @@ function SetSetupObject() {
}
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);
@ -108,6 +139,11 @@ function SetDeleteSmi() {
}
function SetConstructorString() {
set = new Set(keys);
}
function SetAddString() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
@ -138,6 +174,11 @@ function SetDeleteString() {
}
function SetConstructorObject() {
set = new Set(keys);
}
function SetAddObject() {
for (var i = 0; i < N; i++) {
set.add(keys[i], i);
@ -168,6 +209,41 @@ function SetDeleteObject() {
}
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) {

View File

@ -19,6 +19,11 @@ var MapBenchmark = new BenchmarkSuite('WeakMapSetGet-Large', [1e7], [
WeakMapSetupBaseLarge, WeakMapTearDown),
]);
var MapBenchmark = new BenchmarkSuite('WeakMap-Constructor', [1000], [
new Benchmark('Constructor', false, false, 0, WeakMapConstructor, SetupObjectKeyValuePairs,
WeakMapTearDown),
]);
var wm;
@ -46,6 +51,10 @@ function WeakMapTearDown() {
}
function WeakMapConstructor() {
wm = new WeakMap(keyValuePairs);
}
function WeakMapSet() {
for (var i = 0; i < N; i++) {
wm.set(keys[i], i);

View File

@ -12,6 +12,10 @@ var SetBenchmark = new BenchmarkSuite('WeakSet', [1000], [
WeakSetTearDown),
]);
var SetBenchmark = new BenchmarkSuite('WeakSet-Constructor', [1000], [
new Benchmark('Constructor', false, false, 0, WeakSetConstructor, SetupObjectKeys,
WeakSetTearDown),
]);
var ws;
@ -33,6 +37,11 @@ function WeakSetTearDown() {
}
function WeakSetConstructor() {
ws = new WeakSet(keys);
}
function WeakSetAdd() {
for (var i = 0; i < N; i++) {
ws.add(keys[i]);

View File

@ -150,15 +150,20 @@
{"name": "Map-Smi"},
{"name": "Map-String"},
{"name": "Map-Object"},
{"name": "Map-Object-Set-Get-Large"},
{"name": "Map-Double"},
{"name": "Map-Iteration"},
{"name": "Map-Iterator"},
{"name": "Set-Smi"},
{"name": "Set-String"},
{"name": "Set-Object"},
{"name": "Set-Double"},
{"name": "Set-Iteration"},
{"name": "Set-Iterator"},
{"name": "WeakMap"},
{"name": "WeakSet"}
{"name": "WeakMap-Constructor"},
{"name": "WeakSet"},
{"name": "WeakSet-Constructor"}
]
},
{