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

Side by Side Diff: test/js-perf-test/Iterators/forof.js

Issue 641123003: Performance tests for iterators. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix to json file Created 6 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 | Annotate | Revision Log
« no previous file with comments | « test/js-perf-test/Iterators/base.js ('k') | test/js-perf-test/Iterators/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
(Empty)
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
3 // found in the LICENSE file.
4
5 new BenchmarkSuite('ForOf', [1000], [
6 new Benchmark('ArrayValues', false, false, 0, ForOf, ForOfArraySetup, ForOfTea rDown),
7 new Benchmark('ArrayKeys', false, false, 0, ForOf, ForOfArrayKeysSetup, ForOfT earDown),
8 new Benchmark('ArrayEntries', false, false, 0, ForOf, ForOfArrayEntriesSetup, ForOfTearDown),
9 new Benchmark('Uint8Array', false, false, 0, ForOf, ForOfUint8ArraySetup, ForO fTearDown),
10 new Benchmark('Float64Array', false, false, 0, ForOf, ForOfFloat64ArraySetup, ForOfTearDown),
11 new Benchmark('String', false, false, 0, ForOf, ForOfStringSetup, ForOfTearDow n),
12 ]);
13
14
15 var iterable;
16 var N = 100;
17 var expected, result;
18
19
20 function ForOfArraySetupHelper(constructor) {
21 iterable = new constructor(N);
22 for (var i = 0; i < N; i++) iterable[i] = i;
23 expected = N - 1;
24 }
25
26
27 function ForOfArraySetup() {
28 ForOfArraySetupHelper(Array);
29 // Default iterator is values().
30 }
31
32
33 function ForOfArrayKeysSetup() {
34 ForOfArraySetupHelper(Array);
35 iterable = iterable.keys();
36 }
37
38
39 function ForOfArrayEntriesSetup() {
40 ForOfArraySetupHelper(Array);
41 iterable = iterable.entries();
42 expected = [N-1, N-1];
43 }
44
45
46 function ForOfUint8ArraySetup() {
47 ForOfArraySetupHelper(Uint8Array);
48 }
49
50
51 function ForOfFloat64ArraySetup() {
52 ForOfArraySetupHelper(Float64Array);
53 }
54
55
56 function ForOfStringSetup() {
57 iterable = "abcdefhijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ0123456789";
58 expected = "9";
59 }
60
61
62 function Equals(expected, actual) {
63 if (expected === actual) return true;
64 if (typeof expected !== typeof actual) return false;
65 if (typeof expected !== 'object') return false;
66 for (var k of Object.keys(expected)) {
67 if (!(k in actual)) return false;
68 if (!Equals(expected[k], actual[k])) return false;
69 }
70 for (var k of Object.keys(actual)) {
71 if (!(k in expected)) return false;
72 }
73 return true;
74 }
75
76 function ForOfTearDown() {
77 iterable = null;
78 if (!Equals(expected, result)) {
79 throw new Error("Bad result: " + result);
80 }
81 }
82
83
84 function ForOf() {
85 for (var x of iterable) {
86 result = x;
87 }
88 }
OLDNEW
« no previous file with comments | « test/js-perf-test/Iterators/base.js ('k') | test/js-perf-test/Iterators/run.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698