Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: test/js-perf-test/Collections/map.js

Issue 685753004: Add performance tests for Map/Set with String and Object keys (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/js-perf-test/Collections/common.js ('k') | test/js-perf-test/Collections/run.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 var MapBenchmark = new BenchmarkSuite('Map', [1000], [ 6 var MapSmiBenchmark = new BenchmarkSuite('Map-Smi', [1000], [
7 new Benchmark('Set', false, false, 0, MapSet), 7 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/
8 new Benchmark('Has', false, false, 0, MapHas, MapSetup, MapTearDown), 8 new Benchmark('Has', false, false, 0, MapHas, MapSetupSmi, MapTearDown),
9 new Benchmark('Get', false, false, 0, MapGet, MapSetup, MapTearDown), 9 new Benchmark('Get', false, false, 0, MapGet, MapSetupSmi, MapTearDown),
10 new Benchmark('Delete', false, false, 0, MapDelete, MapSetup, MapTearDown), 10 new Benchmark('Delete', false, false, 0, MapDelete, MapSetupSmi, MapTearDown),
11 new Benchmark('ForEach', false, false, 0, MapForEach, MapSetup, MapTearDown), 11 ]);
12
13
14 var MapStringBenchmark = new BenchmarkSuite('Map-String', [1000], [
15 new Benchmark('Set', false, false, 0, MapSet, MapSetupStringBase, MapTearDown) ,
16 new Benchmark('Has', false, false, 0, MapHas, MapSetupString, MapTearDown),
17 new Benchmark('Get', false, false, 0, MapGet, MapSetupString, MapTearDown),
18 new Benchmark('Delete', false, false, 0, MapDelete, MapSetupString, MapTearDow n),
19 ]);
20
21
22 var MapObjectBenchmark = new BenchmarkSuite('Map-Object', [1000], [
23 new Benchmark('Set', false, false, 0, MapSet, MapSetupObjectBase, MapTearDown) ,
24 new Benchmark('Has', false, false, 0, MapHas, MapSetupObject, MapTearDown),
25 new Benchmark('Get', false, false, 0, MapGet, MapSetupObject, MapTearDown),
26 new Benchmark('Delete', false, false, 0, MapDelete, MapSetupObject, MapTearDow n),
27 ]);
28
29
30 var MapIterationBenchmark = new BenchmarkSuite('Map-Iteration', [1000], [
31 new Benchmark('ForEach', false, false, 0, MapForEach, MapSetupSmi, MapTearDown ),
12 ]); 32 ]);
13 33
14 34
15 var map; 35 var map;
16 var N = 10;
17 36
18 37
19 function MapSetup() { 38 function MapSetupSmiBase() {
39 SetupSmiKeys();
20 map = new Map; 40 map = new Map;
21 for (var i = 0; i < N; i++) {
22 map.set(i, i);
23 }
24 } 41 }
25 42
26 43
44 function MapSetupSmi() {
45 MapSetupSmiBase();
46 MapSet();
47 }
48
49
50 function MapSetupStringBase() {
51 SetupStringKeys();
52 map = new Map;
53 }
54
55
56 function MapSetupString() {
57 MapSetupStringBase();
58 MapSet();
59 }
60
61
62 function MapSetupObjectBase() {
63 SetupObjectKeys();
64 map = new Map;
65 }
66
67
68 function MapSetupObject() {
69 MapSetupObjectBase();
70 MapSet();
71 }
72
73
27 function MapTearDown() { 74 function MapTearDown() {
28 map = null; 75 map = null;
29 } 76 }
30 77
31 78
32 function MapSet() { 79 function MapSet() {
33 MapSetup(); 80 for (var i = 0; i < N; i++) {
34 MapTearDown(); 81 map.set(keys[i], i);
82 }
35 } 83 }
36 84
37 85
38 function MapHas() { 86 function MapHas() {
39 for (var i = 0; i < N; i++) { 87 for (var i = 0; i < N; i++) {
40 if (!map.has(i)) { 88 if (!map.has(keys[i])) {
41 throw new Error(); 89 throw new Error();
42 } 90 }
43 } 91 }
44 for (var i = N; i < 2 * N; i++) { 92 for (var i = N; i < 2 * N; i++) {
45 if (map.has(i)) { 93 if (map.has(keys[i])) {
46 throw new Error(); 94 throw new Error();
47 } 95 }
48 } 96 }
49 } 97 }
50 98
51 99
52 function MapGet() { 100 function MapGet() {
53 for (var i = 0; i < N; i++) { 101 for (var i = 0; i < N; i++) {
54 if (map.get(i) !== i) { 102 if (map.get(keys[i]) !== i) {
55 throw new Error(); 103 throw new Error();
56 } 104 }
57 } 105 }
58 for (var i = N; i < 2 * N; i++) { 106 for (var i = N; i < 2 * N; i++) {
59 if (map.get(i) !== undefined) { 107 if (map.get(keys[i]) !== undefined) {
60 throw new Error(); 108 throw new Error();
61 } 109 }
62 } 110 }
63 } 111 }
64 112
65 113
66 function MapDelete() { 114 function MapDelete() {
67 // This is run more than once per setup so we will end up deleting items 115 // This is run more than once per setup so we will end up deleting items
68 // more than once. Therefore, we do not the return value of delete. 116 // more than once. Therefore, we do not the return value of delete.
69 for (var i = 0; i < N; i++) { 117 for (var i = 0; i < N; i++) {
70 map.delete(i); 118 map.delete(keys[i]);
71 } 119 }
72 } 120 }
73 121
74 122
75 function MapForEach() { 123 function MapForEach() {
76 map.forEach(function(v, k) { 124 map.forEach(function(v, k) {
77 if (v !== k) { 125 if (v !== k) {
78 throw new Error(); 126 throw new Error();
79 } 127 }
80 }); 128 });
81 } 129 }
OLDNEW
« no previous file with comments | « test/js-perf-test/Collections/common.js ('k') | test/js-perf-test/Collections/run.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698