| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
| 5 import 'dart:isolate'; | 5 import 'dart:isolate'; |
| 6 | 6 |
| 7 class Fields { | 7 class Fields { |
| 8 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {} | 8 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {} |
| 9 int fld1; | 9 int fld1; |
| 10 final int fld2; | 10 final int fld2; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 class TowersDisk { | 96 class TowersDisk { |
| 97 final int size; | 97 final int size; |
| 98 TowersDisk next; | 98 TowersDisk next; |
| 99 | 99 |
| 100 TowersDisk(size) : this.size = size, next = null {} | 100 TowersDisk(size) : this.size = size, next = null {} |
| 101 } | 101 } |
| 102 | 102 |
| 103 class Towers { | 103 class Towers { |
| 104 List<TowersDisk> piles; | 104 List<TowersDisk> piles; |
| 105 int movesDone; | 105 int movesDone; |
| 106 Towers(int disks) : piles = new List<TowersDisk>(3), movesDone = 0 { | 106 Towers(int disks) |
| 107 : piles = new List<TowersDisk>.fixedLength(3), movesDone = 0 { |
| 107 build(0, disks); | 108 build(0, disks); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void build(int pile, int disks) { | 111 void build(int pile, int disks) { |
| 111 for (var i = disks - 1; i >= 0; i--) { | 112 for (var i = disks - 1; i >= 0; i--) { |
| 112 push(pile, new TowersDisk(i)); | 113 push(pile, new TowersDisk(i)); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 | 116 |
| 116 void push(int pile, TowersDisk disk) { | 117 void push(int pile, TowersDisk disk) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 new TowersBenchmark().report(); | 170 new TowersBenchmark().report(); |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 | 173 |
| 173 // S i e v e | 174 // S i e v e |
| 174 class SieveBenchmark extends BenchmarkBase { | 175 class SieveBenchmark extends BenchmarkBase { |
| 175 const SieveBenchmark() : super("Sieve"); | 176 const SieveBenchmark() : super("Sieve"); |
| 176 | 177 |
| 177 static int sieve(int size) { | 178 static int sieve(int size) { |
| 178 int primeCount = 0; | 179 int primeCount = 0; |
| 179 List<bool> flags = new List<bool>(size + 1); | 180 List<bool> flags = new List<bool>.fixedLength(size + 1); |
| 180 for (int i = 1; i < size; i++) flags[i] = true; | 181 for (int i = 1; i < size; i++) flags[i] = true; |
| 181 for (int i = 2; i < size; i++) { | 182 for (int i = 2; i < size; i++) { |
| 182 if (flags[i]) { | 183 if (flags[i]) { |
| 183 primeCount++; | 184 primeCount++; |
| 184 for (int k = i + 1; k <= size; k += i) | 185 for (int k = i + 1; k <= size; k += i) |
| 185 flags[k - 1] = false; | 186 flags[k - 1] = false; |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 return primeCount; | 189 return primeCount; |
| 189 } | 190 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 for (int k = n - 1; k >= 1; k--) { | 228 for (int k = n - 1; k >= 1; k--) { |
| 228 swap(n, k, list); | 229 swap(n, k, list); |
| 229 doPermute(n - 1, list); | 230 doPermute(n - 1, list); |
| 230 swap(n, k, list); | 231 swap(n, k, list); |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 | 235 |
| 235 int permute(int size) { | 236 int permute(int size) { |
| 236 permuteCount = 0; | 237 permuteCount = 0; |
| 237 List<int> list = new List<int>(size); | 238 List<int> list = new List<int>.fixedLength(size); |
| 238 for (int i = 1; i < size; i++) list[i] = i - 1; | 239 for (int i = 1; i < size; i++) list[i] = i - 1; |
| 239 doPermute(size - 1, list); | 240 doPermute(size - 1, list); |
| 240 return permuteCount; | 241 return permuteCount; |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 | 244 |
| 244 class PermuteBenchmark extends BenchmarkBase { | 245 class PermuteBenchmark extends BenchmarkBase { |
| 245 const PermuteBenchmark() : super("Permute"); | 246 const PermuteBenchmark() : super("Permute"); |
| 246 | 247 |
| 247 void warmup() { | 248 void warmup() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 291 } |
| 291 } else { | 292 } else { |
| 292 q = true; | 293 q = true; |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 return q; | 297 return q; |
| 297 } | 298 } |
| 298 | 299 |
| 299 static void queens() { | 300 static void queens() { |
| 300 List<bool> a = new List<bool>(9); | 301 List<bool> a = new List<bool>.fixedLength(9); |
| 301 List<bool> b = new List<bool>(17); | 302 List<bool> b = new List<bool>.fixedLength(17); |
| 302 List<bool> c = new List<bool>(15); | 303 List<bool> c = new List<bool>.fixedLength(15); |
| 303 List<int> x = new List<int>(9); | 304 List<int> x = new List<int>.fixedLength(9); |
| 304 b[1] = false; | 305 b[1] = false; |
| 305 for (int i = -7; i <= 16; i++) { | 306 for (int i = -7; i <= 16; i++) { |
| 306 if ((i >= 1) && (i <= 8)) a[i] = true; | 307 if ((i >= 1) && (i <= 8)) a[i] = true; |
| 307 if (i >= 2) b[i] = true; | 308 if (i >= 2) b[i] = true; |
| 308 if (i <= 7) c[i + 7] = true; | 309 if (i <= 7) c[i + 7] = true; |
| 309 } | 310 } |
| 310 | 311 |
| 311 if (!tryQueens(1, b, a, c, x)) | 312 if (!tryQueens(1, b, a, c, x)) |
| 312 Error.error("Error in queens"); | 313 Error.error("Error in queens"); |
| 313 } | 314 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 400 } |
| 400 | 401 |
| 401 // | 402 // |
| 402 class SortData { | 403 class SortData { |
| 403 List<int> list; | 404 List<int> list; |
| 404 int min; | 405 int min; |
| 405 int max; | 406 int max; |
| 406 | 407 |
| 407 SortData(int length) { | 408 SortData(int length) { |
| 408 Random r = new Random(); | 409 Random r = new Random(); |
| 409 list = new List<int>(length); | 410 list = new List<int>.fixedLength(length); |
| 410 for (int i = 0; i < length; i++) list[i] = r.random(); | 411 for (int i = 0; i < length; i++) list[i] = r.random(); |
| 411 | 412 |
| 412 int min, max; | 413 int min, max; |
| 413 min = max = list[0]; | 414 min = max = list[0]; |
| 414 for (int i = 0; i < length; i++) { | 415 for (int i = 0; i < length; i++) { |
| 415 int e = list[i]; | 416 int e = list[i]; |
| 416 if (e > max) max = e; | 417 if (e > max) max = e; |
| 417 if (e < min) min = e; | 418 if (e < min) min = e; |
| 418 } | 419 } |
| 419 | 420 |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 var idx = i; | 1311 var idx = i; |
| 1311 remote.call(sentObject).then(expectAsync1((var receivedObject) { | 1312 remote.call(sentObject).then(expectAsync1((var receivedObject) { |
| 1312 MessageTest.VerifyObject(idx, receivedObject); | 1313 MessageTest.VerifyObject(idx, receivedObject); |
| 1313 })); | 1314 })); |
| 1314 } | 1315 } |
| 1315 | 1316 |
| 1316 // Send recursive objects and receive them back. | 1317 // Send recursive objects and receive them back. |
| 1317 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; | 1318 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; |
| 1318 List local_list2 = [null, local_list1, local_list1 ]; | 1319 List local_list2 = [null, local_list1, local_list1 ]; |
| 1319 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; | 1320 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; |
| 1320 List sendObject = new List(5); | 1321 List sendObject = new List.fixedLength(5); |
| 1321 sendObject[0] = local_list1; | 1322 sendObject[0] = local_list1; |
| 1322 sendObject[1] = sendObject; | 1323 sendObject[1] = sendObject; |
| 1323 sendObject[2] = local_list2; | 1324 sendObject[2] = local_list2; |
| 1324 sendObject[3] = sendObject; | 1325 sendObject[3] = sendObject; |
| 1325 sendObject[4] = local_list3; | 1326 sendObject[4] = local_list3; |
| 1326 remote.call(sendObject).then((var replyObject) { | 1327 remote.call(sendObject).then((var replyObject) { |
| 1327 Expect.equals(true, sendObject is List); | 1328 Expect.equals(true, sendObject is List); |
| 1328 Expect.equals(true, replyObject is List); | 1329 Expect.equals(true, replyObject is List); |
| 1329 Expect.equals(sendObject.length, replyObject.length); | 1330 Expect.equals(sendObject.length, replyObject.length); |
| 1330 Expect.equals(true, identical(replyObject[1], replyObject)); | 1331 Expect.equals(true, identical(replyObject[1], replyObject)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 })); | 1435 })); |
| 1435 for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i); | 1436 for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i); |
| 1436 }); | 1437 }); |
| 1437 } | 1438 } |
| 1438 | 1439 |
| 1439 | 1440 |
| 1440 class MandelbrotState { | 1441 class MandelbrotState { |
| 1441 | 1442 |
| 1442 MandelbrotState() { | 1443 MandelbrotState() { |
| 1443 _result = new List<List<int>>(N); | 1444 _result = new List<List<int>>(N); |
| 1444 _lineProcessedBy = new List<LineProcessorClient>(N); | 1445 _lineProcessedBy = new List<LineProcessorClient>.fixedLength(N); |
| 1445 _sent = 0; | 1446 _sent = 0; |
| 1446 _missing = N; | 1447 _missing = N; |
| 1447 _validated = new Completer<bool>(); | 1448 _validated = new Completer<bool>(); |
| 1448 } | 1449 } |
| 1449 | 1450 |
| 1450 void startClient(int id) { | 1451 void startClient(int id) { |
| 1451 assert(_sent < N); | 1452 assert(_sent < N); |
| 1452 final client = new LineProcessorClient(this, id); | 1453 final client = new LineProcessorClient(this, id); |
| 1453 client.processLine(_sent++); | 1454 client.processLine(_sent++); |
| 1454 } | 1455 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 } | 1515 } |
| 1515 | 1516 |
| 1516 MandelbrotState _state; | 1517 MandelbrotState _state; |
| 1517 int _id; | 1518 int _id; |
| 1518 SendPort _port; | 1519 SendPort _port; |
| 1519 } | 1520 } |
| 1520 | 1521 |
| 1521 List<int> processLine(int y) { | 1522 List<int> processLine(int y) { |
| 1522 double inverseN = 2.0 / N; | 1523 double inverseN = 2.0 / N; |
| 1523 double Civ = y * inverseN - 1.0; | 1524 double Civ = y * inverseN - 1.0; |
| 1524 List<int> result = new List<int>(N); | 1525 List<int> result = new List<int>.fixedLength(N); |
| 1525 for (int x = 0; x < N; x++) { | 1526 for (int x = 0; x < N; x++) { |
| 1526 double Crv = x * inverseN - 1.5; | 1527 double Crv = x * inverseN - 1.5; |
| 1527 | 1528 |
| 1528 double Zrv = Crv; | 1529 double Zrv = Crv; |
| 1529 double Ziv = Civ; | 1530 double Ziv = Civ; |
| 1530 | 1531 |
| 1531 double Trv = Crv * Crv; | 1532 double Trv = Crv * Crv; |
| 1532 double Tiv = Civ * Civ; | 1533 double Tiv = Civ * Civ; |
| 1533 | 1534 |
| 1534 int i = 49; | 1535 int i = 49; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1548 void processLines() { | 1549 void processLines() { |
| 1549 port.receive((message, SendPort replyTo) { | 1550 port.receive((message, SendPort replyTo) { |
| 1550 if (message == TERMINATION_MESSAGE) { | 1551 if (message == TERMINATION_MESSAGE) { |
| 1551 assert(replyTo == null); | 1552 assert(replyTo == null); |
| 1552 port.close(); | 1553 port.close(); |
| 1553 } else { | 1554 } else { |
| 1554 replyTo.send(processLine(message), null); | 1555 replyTo.send(processLine(message), null); |
| 1555 } | 1556 } |
| 1556 }); | 1557 }); |
| 1557 } | 1558 } |
| OLD | NEW |