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

Side by Side Diff: tests/language/optimization_test.dart

Issue 18563006: More tests updated to optimize code (Part 2). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // Test various optimizations and deoptimizations of optimizing compiler.. 4 // Test various optimizations and deoptimizations of optimizing compiler..
5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr
5 6
6 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
7 8
8 addThem(a, b) { 9 addThem(a, b) {
9 return a + b; 10 return a + b;
10 } 11 }
11 12
12 isItInt(a) { 13 isItInt(a) {
13 return a is int; 14 return a is int;
14 } 15 }
(...skipping 24 matching lines...) Expand all
39 40
40 class StringPlus { 41 class StringPlus {
41 const StringPlus(String this._val); 42 const StringPlus(String this._val);
42 operator + (right) => new StringPlus("${_val}${right}"); 43 operator + (right) => new StringPlus("${_val}${right}");
43 toString() => _val; 44 toString() => _val;
44 45
45 final String _val; 46 final String _val;
46 } 47 }
47 48
48 main() { 49 main() {
49 for (int i = 0; i < 2000; i++) { 50 for (int i = 0; i < 20; i++) {
50 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString()); 51 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString());
51 Expect.equals(true, isItInt(5)); 52 Expect.equals(true, isItInt(5));
52 } 53 }
53 Expect.equals(8, addThem(3, 5)); 54 Expect.equals(8, addThem(3, 5));
54 for (int i = 0; i < 2000; i++) { 55 for (int i = 0; i < 20; i++) {
55 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString()); 56 Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString());
56 Expect.equals(8, addThem(3, 5)); 57 Expect.equals(8, addThem(3, 5));
57 } 58 }
58 for (int i = -500; i < 500; i++) { 59 for (int i = -10; i < 10; i++) {
59 var r = doNeg(i); 60 var r = doNeg(i);
60 var p = doNeg(r); 61 var p = doNeg(r);
61 Expect.equals(i, p); 62 Expect.equals(i, p);
62 } 63 }
63 var maxSmi = (1 << 30) - 1; 64 var maxSmi = (1 << 30) - 1;
64 Expect.equals(maxSmi, doNeg(doNeg(maxSmi))); 65 Expect.equals(maxSmi, doNeg(doNeg(maxSmi)));
65 // Deoptimize because of overflow. 66 // Deoptimize because of overflow.
66 var minInt = -(1 << 30); 67 var minInt = -(1 << 30);
67 Expect.equals(minInt, doNeg(doNeg(minInt))); 68 Expect.equals(minInt, doNeg(doNeg(minInt)));
68 69
69 for (int i = 0; i < 1000; i++) { 70 for (int i = 0; i < 20; i++) {
70 Expect.equals(false, doNot(true)); 71 Expect.equals(false, doNot(true));
71 Expect.equals(true, doNot(doNot(true))); 72 Expect.equals(true, doNot(doNot(true)));
72 } 73 }
73 for (int i = 0; i < 1000; i++) { 74 for (int i = 0; i < 20; i++) {
74 Expect.equals(-57, doBitNot(56)); 75 Expect.equals(-57, doBitNot(56));
75 Expect.equals(55, doBitNot(-56)); 76 Expect.equals(55, doBitNot(-56));
76 } 77 }
77 78
78 for (int i = 0; i < 2000; i++) { 79 for (int i = 0; i < 20; i++) {
79 Expect.equals(-2.2, doNeg2(2.2)); 80 Expect.equals(-2.2, doNeg2(2.2));
80 } 81 }
81 // Deoptimize. 82 // Deoptimize.
82 Expect.equals(-5, doNeg2(5)); 83 Expect.equals(-5, doNeg2(5));
83 84
84 var fixed = new List(10); 85 var fixed = new List(10);
85 var growable = [1, 2, 3, 4, 5]; 86 var growable = [1, 2, 3, 4, 5];
86 87
87 for (int i = 0; i < 2000; i++) { 88 for (int i = 0; i < 20; i++) {
88 doStore1(fixed, 7); 89 doStore1(fixed, 7);
89 Expect.equals(7, fixed[1]); 90 Expect.equals(7, fixed[1]);
90 doStore2(growable, 12); 91 doStore2(growable, 12);
91 Expect.equals(12, growable[2]); 92 Expect.equals(12, growable[2]);
92 } 93 }
93 94
94 // Deoptimize. 95 // Deoptimize.
95 doStore1(growable, 8); 96 doStore1(growable, 8);
96 Expect.equals(8, growable[1]); 97 Expect.equals(8, growable[1]);
97 doStore2(fixed, 101); 98 doStore2(fixed, 101);
98 Expect.equals(101, fixed[2]); 99 Expect.equals(101, fixed[2]);
99 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698