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