| OLD | NEW |
| 1 part of dromaeo; | 1 part of dromaeo; |
| 2 | 2 |
| 3 typedef void Test(); | 3 typedef void Test(); |
| 4 typedef void Operation(); | 4 typedef void Operation(); |
| 5 typedef void Reporter(Map<String, Result> results); | 5 typedef void Reporter(Map<String, Result> results); |
| 6 | 6 |
| 7 class Suite { | 7 class Suite { |
| 8 /** | 8 /** |
| 9 * Ctor. | 9 * Ctor. |
| 10 * [:_window:] The window of the suite. | 10 * [:_window:] The window of the suite. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 */ | 44 */ |
| 45 Suite test(String name, Test test_) { | 45 Suite test(String name, Test test_) { |
| 46 _nTests++; | 46 _nTests++; |
| 47 // Don't execute the test immediately. | 47 // Don't execute the test immediately. |
| 48 return _addOperation(() { | 48 return _addOperation(() { |
| 49 // List of number of runs in seconds. | 49 // List of number of runs in seconds. |
| 50 List<double> runsPerSecond = new List<double>(); | 50 List<double> runsPerSecond = new List<double>(); |
| 51 | 51 |
| 52 // Run the test several times. | 52 // Run the test several times. |
| 53 try { | 53 try { |
| 54 // TODO(antonm): use .setTimeout to schedule next run as JS | 54 // TODO(antonm): use timer to schedule next run as JS |
| 55 // version does. That allows to report the intermidiate results | 55 // version does. That allows to report the intermidiate results |
| 56 // more smoothly as well. | 56 // more smoothly as well. |
| 57 for (int i = 0; i < _N_RUNS; i++) { | 57 for (int i = 0; i < _N_RUNS; i++) { |
| 58 int runs = 0; | 58 int runs = 0; |
| 59 final int start = new DateTime.now().millisecondsSinceEpoch; | 59 final int start = new DateTime.now().millisecondsSinceEpoch; |
| 60 | 60 |
| 61 int cur = new DateTime.now().millisecondsSinceEpoch; | 61 int cur = new DateTime.now().millisecondsSinceEpoch; |
| 62 while ((cur - start) < 1000) { | 62 while ((cur - start) < 1000) { |
| 63 test_(); | 63 test_(); |
| 64 cur = new DateTime.now().millisecondsSinceEpoch; | 64 cur = new DateTime.now().millisecondsSinceEpoch; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 _postMessage('inited', { 'nTests': _nTests }); | 83 _postMessage('inited', { 'nTests': _nTests }); |
| 84 | 84 |
| 85 } | 85 } |
| 86 | 86 |
| 87 _run() { | 87 _run() { |
| 88 int currentOperation = 0; | 88 int currentOperation = 0; |
| 89 handler() { | 89 handler() { |
| 90 if (currentOperation < _operations.length) { | 90 if (currentOperation < _operations.length) { |
| 91 _operations[currentOperation](); | 91 _operations[currentOperation](); |
| 92 currentOperation++; | 92 currentOperation++; |
| 93 _window.setTimeout(handler, 1); | 93 new Timer(const Duration(milliseconds: 1), handler); |
| 94 } else { | 94 } else { |
| 95 _postMessage('over'); | 95 _postMessage('over'); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 _window.setTimeout(handler, 0); | 98 Timer.run(handler); |
| 99 } | 99 } |
| 100 | 100 |
| 101 _reportTestResults(String name, Result result) { | 101 _reportTestResults(String name, Result result) { |
| 102 _nRanTests++; | 102 _nRanTests++; |
| 103 _postMessage('result', { | 103 _postMessage('result', { |
| 104 'testName': name, | 104 'testName': name, |
| 105 'mean': result.mean, | 105 'mean': result.mean, |
| 106 'error': result.error, | 106 'error': result.error, |
| 107 'percent': (100.0 * _nRanTests / _nTests) | 107 'percent': (100.0 * _nRanTests / _nTests) |
| 108 }); | 108 }); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 | 123 |
| 124 List<Operation> _operations; | 124 List<Operation> _operations; |
| 125 int _nTests; | 125 int _nTests; |
| 126 int _nRanTests; | 126 int _nRanTests; |
| 127 | 127 |
| 128 Suite _addOperation(Operation operation) { | 128 Suite _addOperation(Operation operation) { |
| 129 _operations.add(operation); | 129 _operations.add(operation); |
| 130 return this; | 130 return this; |
| 131 } | 131 } |
| 132 } | 132 } |
| OLD | NEW |