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

Side by Side Diff: test/js-perf-test/StringIterators/string-iterator.js

Issue 2364743003: [js-perf-test] add microbenchmarks for String Iterators (Closed)
Patch Set: Created 4 years, 2 months 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
« no previous file with comments | « test/js-perf-test/StringIterators/run.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function assert(expression, message) {
6 if (typeof expression === "string" && message === void 0) {
7 message = expression;
8 expression = eval(expression);
9 }
10
11 if (!expression) {
12 var lines = ["Benchmark Error"];
13 if (message !== void 0) {
14 lines = ["Benchmark Error:", String(message)];
15 }
16 throw new Error(lines.join("\n"));
17 }
18 return true;
19 }
20
21 assert.same = function(expected, actual, message) {
22 var isSame =
23 expected === actual || typeof expected !== expected && actual !== actual;
24 if (!isSame) {
25 var details = `Expected: ${String(expected)}\n` +
26 `But found: ${String(actual)}`;
27 var lines = ["Benchmark Error:", details];
28 if (message !== void 0) {
29 lines = ["Benchmark Error:", details, "", String(message)];
30 }
31 throw new Error(lines.join("\n"));
32 }
33 return true;
34 }
35
36 new BenchmarkSuite('Spread_OneByteShort', [1000], [
37 new Benchmark('test', false, false, 0,
38 Spread_OneByteShort, Spread_OneByteShortSetup,
39 Spread_OneByteShortTearDown),
40 ]);
41
42 var result;
43 var string;
44 function Spread_OneByteShortSetup() {
45 result = undefined;
46 string = "Alphabet-Soup";
47 }
48
49 function Spread_OneByteShort() {
50 result = [...string];
51 }
52
53 function Spread_OneByteShortTearDown() {
54 var expected = "A|l|p|h|a|b|e|t|-|S|o|u|p";
55 return assert("Array.isArray(result)")
56 && assert.same(expected, result.join("|"));
57 }
58
59 // ----------------------------------------------------------------------------
60
61 new BenchmarkSuite('Spread_TwoByteShort', [1000], [
62 new Benchmark('test', false, false, 0,
63 Spread_TwoByteShort, Spread_TwoByteShortSetup,
64 Spread_TwoByteShortTearDown),
65 ]);
66
67 function Spread_TwoByteShortSetup() {
68 result = undefined;
69 string = "\u5FCD\u8005\u306E\u653B\u6483";
70 }
71
72 function Spread_TwoByteShort() {
73 result = [...string];
74 }
75
76 function Spread_TwoByteShortTearDown() {
77 var expected = "\u5FCD|\u8005|\u306E|\u653B|\u6483";
78 return assert("Array.isArray(result)")
79 && assert.same(expected, result.join("|"));
80 }
81
82 // ----------------------------------------------------------------------------
83
84 new BenchmarkSuite('Spread_WithSurrogatePairsShort', [1000], [
85 new Benchmark('test', false, false, 0,
86 Spread_WithSurrogatePairsShort,
87 Spread_WithSurrogatePairsShortSetup,
88 Spread_WithSurrogatePairsShortTearDown),
89 ]);
90
91 function Spread_WithSurrogatePairsShortSetup() {
92 result = undefined;
93 string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F";
94 }
95
96 function Spread_WithSurrogatePairsShort() {
97 result = [...string];
98 }
99
100 function Spread_WithSurrogatePairsShortTearDown() {
101 var expected =
102 "\uD83C\uDF1F|\u5FCD|\u8005|\u306E|\u653B|\u6483|\uD83C\uDF1F";
103 return assert("Array.isArray(result)")
104 && assert.same(expected, result.join("|"));
105 }
106
107 // ----------------------------------------------------------------------------
108
109 new BenchmarkSuite('ForOf_OneByteShort', [1000], [
110 new Benchmark('test', false, false, 0,
111 ForOf_OneByteShort, ForOf_OneByteShortSetup,
112 ForOf_OneByteShortTearDown),
113 ]);
114
115 function ForOf_OneByteShortSetup() {
116 result = undefined;
117 string = "Alphabet-Soup";
118 }
119
120 function ForOf_OneByteShort() {
121 result = "";
122 for (var c of string) result += c;
123 }
124
125 function ForOf_OneByteShortTearDown() {
126 return assert.same(string, result);
127 }
128
129 // ----------------------------------------------------------------------------
130
131 new BenchmarkSuite('ForOf_TwoByteShort', [1000], [
132 new Benchmark('test', false, false, 0,
133 ForOf_TwoByteShort, ForOf_TwoByteShortSetup,
134 ForOf_TwoByteShortTearDown),
135 ]);
136
137 function ForOf_TwoByteShortSetup() {
138 result = undefined;
139 string = "\u5FCD\u8005\u306E\u653B\u6483";
140 }
141
142 function ForOf_TwoByteShort() {
143 result = "";
144 for (var c of string) result += c;
145 }
146
147 function ForOf_TwoByteShortTearDown() {
148 return assert.same(string, result);
149 }
150
151 // ----------------------------------------------------------------------------
152
153 new BenchmarkSuite('ForOf_WithSurrogatePairsShort', [1000], [
154 new Benchmark('test', false, false, 0,
155 ForOf_WithSurrogatePairsShort,
156 ForOf_WithSurrogatePairsShortSetup,
157 ForOf_WithSurrogatePairsShortTearDown),
158 ]);
159
160 function ForOf_WithSurrogatePairsShortSetup() {
161 result = undefined;
162 string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F";
163 }
164
165 function ForOf_WithSurrogatePairsShort() {
166 result = "";
167 for (var c of string) result += c;
168 }
169
170 function ForOf_WithSurrogatePairsShortTearDown() {
171 return assert.same(string, result);
172 }
173
174 // ----------------------------------------------------------------------------
175
176 new BenchmarkSuite('ForOf_OneByteLong', [1000], [
177 new Benchmark('test', false, false, 0,
178 ForOf_OneByteLong, ForOf_OneByteLongSetup,
179 ForOf_OneByteLongTearDown),
180 ]);
181
182 function ForOf_OneByteLongSetup() {
183 result = undefined;
184 string = "Alphabet-Soup|".repeat(128);
185 }
186
187 function ForOf_OneByteLong() {
188 result = "";
189 for (var c of string) result += c;
190 }
191
192 function ForOf_OneByteLongTearDown() {
193 return assert.same(string, result);
194 }
195
196 // ----------------------------------------------------------------------------
197
198 new BenchmarkSuite('ForOf_TwoByteLong', [1000], [
199 new Benchmark('test', false, false, 0,
200 ForOf_OneByteLong, ForOf_OneByteLongSetup,
201 ForOf_OneByteLongTearDown),
202 ]);
203
204 function ForOf_TwoByteLongSetup() {
205 result = undefined;
206 string = "\u5FCD\u8005\u306E\u653B\u6483".repeat(128);
207 }
208
209 function ForOf_TwoByteLong() {
210 result = "";
211 for (var c of string) result += c;
212 }
213
214 function ForOf_TwoByteLongTearDown() {
215 return assert.same(string, result);
216 }
217
218 // ----------------------------------------------------------------------------
219
220 new BenchmarkSuite('ForOf_WithSurrogatePairsLong', [1000], [
221 new Benchmark('test', false, false, 0,
222 ForOf_WithSurrogatePairsLong, ForOf_WithSurrogatePairsLongSetup,
223 ForOf_WithSurrogatePairsLongTearDown),
224 ]);
225
226 function ForOf_WithSurrogatePairsLongSetup() {
227 result = undefined;
228 string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F|"
229 .repeat(128);
230 }
231
232 function ForOf_WithSurrogatePairsLong() {
233 result = "";
234 for (var c of string) result += c;
235 }
236
237 function ForOf_WithSurrogatePairsLongTearDown() {
238 return assert.same(string, result);
239 }
OLDNEW
« no previous file with comments | « test/js-perf-test/StringIterators/run.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698