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

Side by Side Diff: test/js-perf-test/PropertyQueries/property-queries.js

Issue 1988673002: [js-perf-test] Fix JSTests/PropertyQueries microbenchmark. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | 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
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 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 function ObjectWithKeys(count, keyOffset = 0, keyGen) { 5 function ObjectWithKeys(count, keyOffset = 0, keyGen) {
6 var o = {}; 6 var body = "";
7 for (var i = 0; i < count; i++) { 7 for (var i = 0; i < count; i++) {
8 var key = keyGen(i + keyOffset); 8 var key = keyGen(i + keyOffset);
9 o[key] = "value"; 9 if (typeof key === "string") {
10 body += `this.${key} = 0\n`;
11 } else {
12 body += `this[${key}] = 0\n`;
13 }
10 } 14 }
11 return o; 15 var f = new Function(body);
16 return new f();
12 } 17 }
13 18
14 function ObjectWithProperties(count, keyOffset) { 19 function ObjectWithProperties(count, keyOffset) {
15 return ObjectWithKeys(count, keyOffset, (key) => "key" + key ); 20 return ObjectWithKeys(count, keyOffset, (key) => "key" + key );
16 } 21 }
17 22
18 function ObjectWithElements(count, keyOffset) { 23 function ObjectWithElements(count, keyOffset) {
19 return ObjectWithKeys(count, keyOffset, (key) => key ); 24 return ObjectWithKeys(count, keyOffset, (key) => key );
20 } 25 }
21 26
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 164 }
160 165
161 166
162 var TestData = []; 167 var TestData = [];
163 168
164 [true, false].forEach((cachable) => { 169 [true, false].forEach((cachable) => {
165 [OBJ_MODE_FAST, OBJ_MODE_SLOW].forEach((obj_mode) => { 170 [OBJ_MODE_FAST, OBJ_MODE_SLOW].forEach((obj_mode) => {
166 var proto_mode = cachable ? "" : "-with-slow-proto"; 171 var proto_mode = cachable ? "" : "-with-slow-proto";
167 var name = `${obj_mode}-obj${proto_mode}`; 172 var name = `${obj_mode}-obj${proto_mode}`;
168 var objects = []; 173 var objects = [];
169 [10, 50, 100, 200, 500, 1000].forEach((prop_count) => { 174 [10, 50, 100, 200, 500].forEach((prop_count) => {
170 // Create object with prop_count properties and prop_count elements. 175 // Create object with prop_count properties and prop_count elements.
171 obj = ObjectWithProtoKeys(5, prop_count * 2, cachable, 176 obj = ObjectWithProtoKeys(5, prop_count * 2, cachable,
172 ObjectWithMixedKeys); 177 ObjectWithMixedKeys);
173 if (obj_mode == OBJ_MODE_SLOW) { 178 if (obj_mode == OBJ_MODE_SLOW) {
174 obj = MakeDictionaryMode(obj); 179 obj = MakeDictionaryMode(obj);
175 } 180 }
176 objects.push(obj); 181 objects.push(obj);
177 }); 182 });
178 TestData.push({name, objects}); 183 TestData.push({name, objects});
179 }); 184 });
180 }); 185 });
181 186
182 187
183 // ============================================================================ 188 // ============================================================================
184 189
185 function CreateTestFunction(template, object, keys) { 190 function CreateTestFunction(template, object, keys) {
186 // Force a new function for each test-object to avoid side-effects due to ICs. 191 // Force a new function for each test-object to avoid side-effects due to ICs.
187 var text = "// random comment " + Math.random() + "\n" + 192 var text = "// random comment " + Math.random() + "\n" +
188 template(object, keys); 193 template(object, keys);
189 var func = new Function("object", "keys", text); 194 var func = new Function("object", "keys", text);
190 return () => func(object, keys); 195 return () => func(object, keys);
191 } 196 }
192 197
198 function CombineTestFunctions(tests) {
199 return () => {
200 for (var i = 0; i < tests.length; i++ ) {
201 tests[i]();
202 }
203 };
204 }
205
193 var TestFunctions = [ 206 var TestFunctions = [
194 { 207 {
195 name: "in", 208 name: "in",
196 // Query all keys. 209 // Query all keys.
197 keys: (object) => Object.keys(object), 210 keys: (object) => Object.keys(object),
198 template: (object, keys) => { 211 template: (object, keys) => {
199 var lines = [ 212 var lines = [
200 `var result = true;`, 213 `var result = true;`,
201 `for (var i = 0; i < keys.length; i++) {`, 214 `for (var i = 0; i < keys.length; i++) {`,
202 ` var key = keys[i];`, 215 ` var key = keys[i];`,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 247
235 for (var test_function_desc of TestFunctions) { 248 for (var test_function_desc of TestFunctions) {
236 var test_function_name = test_function_desc.name; 249 var test_function_name = test_function_desc.name;
237 250
238 for (var query_kind of TestQueries) { 251 for (var query_kind of TestQueries) {
239 var benchmarks = []; 252 var benchmarks = [];
240 var suit_name = test_function_name + "--" + query_kind; 253 var suit_name = test_function_name + "--" + query_kind;
241 for (var test_data of TestData) { 254 for (var test_data of TestData) {
242 var name = suit_name + "--" + test_data.name; 255 var name = suit_name + "--" + test_data.name;
243 256
257 var tests = [];
244 for (var object of test_data.objects) { 258 for (var object of test_data.objects) {
245 var keys = test_function_desc.keys(object); 259 var keys = test_function_desc.keys(object);
246 keys = MakeKeyQueries(keys, query_kind); 260 keys = MakeKeyQueries(keys, query_kind);
247 261
248 var test_function = CreateTestFunction(test_function_desc.template, 262 var test = CreateTestFunction(test_function_desc.template, object,
249 object, keys); 263 keys);
250 264 tests.push(test);
251 var benchmark = new Benchmark(name, false, true, 400, test_function);
252 benchmarks.push(benchmark);
253 } 265 }
266 var run_function = CombineTestFunctions(tests);
267 var benchmark = new Benchmark(name, false, false, 0, run_function);
268 benchmarks.push(benchmark);
254 } 269 }
255 Benchmarks.push(new BenchmarkSuite(suit_name, [100], benchmarks)); 270 Benchmarks.push(new BenchmarkSuite(suit_name, [100], benchmarks));
256 } 271 }
257 } 272 }
258 273
259 // ============================================================================ 274 // ============================================================================
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698