Index: test/js-perf-test/Collections/map.js |
diff --git a/test/js-perf-test/Collections/map.js b/test/js-perf-test/Collections/map.js |
index b310a719025ee98c201148f51100a177b8a5ca17..1bba20906dc6ab1ebbe1ffa7161312a89ab39d85 100644 |
--- a/test/js-perf-test/Collections/map.js |
+++ b/test/js-perf-test/Collections/map.js |
@@ -3,24 +3,71 @@ |
// found in the LICENSE file. |
-var MapBenchmark = new BenchmarkSuite('Map', [1000], [ |
- new Benchmark('Set', false, false, 0, MapSet), |
- new Benchmark('Has', false, false, 0, MapHas, MapSetup, MapTearDown), |
- new Benchmark('Get', false, false, 0, MapGet, MapSetup, MapTearDown), |
- new Benchmark('Delete', false, false, 0, MapDelete, MapSetup, MapTearDown), |
- new Benchmark('ForEach', false, false, 0, MapForEach, MapSetup, MapTearDown), |
+var MapSmiBenchmark = new BenchmarkSuite('Map-Smi', [1000], [ |
+ new Benchmark('Set', false, false, 0, MapSet, MapSetupSmiBase, MapTearDown), |
Dmitry Lomov (no reviews)
2014/10/29 10:02:25
In this perf test, you reuse MapSet/MapHas/MapGet/
|
+ new Benchmark('Has', false, false, 0, MapHas, MapSetupSmi, MapTearDown), |
+ new Benchmark('Get', false, false, 0, MapGet, MapSetupSmi, MapTearDown), |
+ new Benchmark('Delete', false, false, 0, MapDelete, MapSetupSmi, MapTearDown), |
+]); |
+ |
+ |
+var MapStringBenchmark = new BenchmarkSuite('Map-String', [1000], [ |
+ new Benchmark('Set', false, false, 0, MapSet, MapSetupStringBase, MapTearDown), |
+ new Benchmark('Has', false, false, 0, MapHas, MapSetupString, MapTearDown), |
+ new Benchmark('Get', false, false, 0, MapGet, MapSetupString, MapTearDown), |
+ new Benchmark('Delete', false, false, 0, MapDelete, MapSetupString, MapTearDown), |
+]); |
+ |
+ |
+var MapObjectBenchmark = new BenchmarkSuite('Map-Object', [1000], [ |
+ new Benchmark('Set', false, false, 0, MapSet, MapSetupObjectBase, MapTearDown), |
+ new Benchmark('Has', false, false, 0, MapHas, MapSetupObject, MapTearDown), |
+ new Benchmark('Get', false, false, 0, MapGet, MapSetupObject, MapTearDown), |
+ new Benchmark('Delete', false, false, 0, MapDelete, MapSetupObject, MapTearDown), |
+]); |
+ |
+ |
+var MapIterationBenchmark = new BenchmarkSuite('Map-Iteration', [1000], [ |
+ new Benchmark('ForEach', false, false, 0, MapForEach, MapSetupSmi, MapTearDown), |
]); |
var map; |
-var N = 10; |
-function MapSetup() { |
+function MapSetupSmiBase() { |
+ SetupSmiKeys(); |
map = new Map; |
- for (var i = 0; i < N; i++) { |
- map.set(i, i); |
- } |
+} |
+ |
+ |
+function MapSetupSmi() { |
+ MapSetupSmiBase(); |
+ MapSet(); |
+} |
+ |
+ |
+function MapSetupStringBase() { |
+ SetupStringKeys(); |
+ map = new Map; |
+} |
+ |
+ |
+function MapSetupString() { |
+ MapSetupStringBase(); |
+ MapSet(); |
+} |
+ |
+ |
+function MapSetupObjectBase() { |
+ SetupObjectKeys(); |
+ map = new Map; |
+} |
+ |
+ |
+function MapSetupObject() { |
+ MapSetupObjectBase(); |
+ MapSet(); |
} |
@@ -30,19 +77,20 @@ function MapTearDown() { |
function MapSet() { |
- MapSetup(); |
- MapTearDown(); |
+ for (var i = 0; i < N; i++) { |
+ map.set(keys[i], i); |
+ } |
} |
function MapHas() { |
for (var i = 0; i < N; i++) { |
- if (!map.has(i)) { |
+ if (!map.has(keys[i])) { |
throw new Error(); |
} |
} |
for (var i = N; i < 2 * N; i++) { |
- if (map.has(i)) { |
+ if (map.has(keys[i])) { |
throw new Error(); |
} |
} |
@@ -51,12 +99,12 @@ function MapHas() { |
function MapGet() { |
for (var i = 0; i < N; i++) { |
- if (map.get(i) !== i) { |
+ if (map.get(keys[i]) !== i) { |
throw new Error(); |
} |
} |
for (var i = N; i < 2 * N; i++) { |
- if (map.get(i) !== undefined) { |
+ if (map.get(keys[i]) !== undefined) { |
throw new Error(); |
} |
} |
@@ -67,7 +115,7 @@ function MapDelete() { |
// 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(i); |
+ map.delete(keys[i]); |
} |
} |