| OLD | NEW |
| 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'dart:fletch'; | 5 import 'dart:dartino'; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 const int PROCESSES = 1000; | 9 const int PROCESSES = 1000; |
| 10 const int MESSAGES = 100; | 10 const int MESSAGES = 100; |
| 11 | 11 |
| 12 void main() { | 12 void main() { |
| 13 Stopwatch watch = new Stopwatch()..start(); | 13 Stopwatch watch = new Stopwatch()..start(); |
| 14 var channel = new Channel(); | 14 var channel = new Channel(); |
| 15 var port = new Port(channel); | 15 var port = new Port(channel); |
| 16 for (int i = 0; i < PROCESSES; i++) { | 16 for (int i = 0; i < PROCESSES; i++) { |
| 17 Process.spawnDetached(() => processRun(port)); | 17 Process.spawnDetached(() => processRun(port)); |
| 18 } | 18 } |
| 19 int done = 0; | 19 int done = 0; |
| 20 while (done < PROCESSES) { | 20 while (done < PROCESSES) { |
| 21 int i = channel.receive(); | 21 int i = channel.receive(); |
| 22 if (i == 0) done ++; | 22 if (i == 0) done ++; |
| 23 } | 23 } |
| 24 print("Took ${watch.elapsedMicroseconds} us to run $PROCESSES processes with " | 24 print("Took ${watch.elapsedMicroseconds} us to run $PROCESSES processes with " |
| 25 "$MESSAGES messages."); | 25 "$MESSAGES messages."); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void processRun(Port output) { | 28 void processRun(Port output) { |
| 29 for (int i = MESSAGES; i >= 0; i--) { | 29 for (int i = MESSAGES; i >= 0; i--) { |
| 30 output.send(i); | 30 output.send(i); |
| 31 } | 31 } |
| 32 } | 32 } |
| OLD | NEW |