Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library test.timing.simple; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import '../timing_framework.dart'; | |
| 10 | |
| 11 /** | |
| 12 * Perform the timing test, printing the minimum time to the output. | |
|
scheglov
2014/10/03 16:46:14
Not only the minimum time.
Brian Wilkerson
2014/10/03 17:17:37
Done
| |
| 13 */ | |
| 14 void main(List<String> args) { | |
| 15 SimpleTest test = new SimpleTest(); | |
| 16 test.run().then((TimingResult result) { | |
| 17 print('minTime = ${result.minTime}'); | |
| 18 print('averageTime = ${result.averageTime}'); | |
| 19 print('maxTime = ${result.maxTime}'); | |
| 20 print('standardDeviation = ${result.standardDeviation}'); | |
| 21 }); | |
| 22 } | |
| 23 | |
| 24 /** | |
| 25 * A test of how long it takes to get code completion results after making a | |
| 26 * minor change inside a method body. | |
| 27 */ | |
| 28 class SimpleTest extends TimingTest { | |
| 29 /** | |
| 30 * The path to the file in which code completion is to be performed. | |
| 31 */ | |
| 32 String mainFilePath; | |
| 33 | |
| 34 /** | |
| 35 * The original content of the file. | |
| 36 */ | |
| 37 String originalContent; | |
| 38 | |
| 39 /** | |
| 40 * The offset of the cursor when requesting code completion. | |
| 41 */ | |
| 42 int cursorOffset; | |
| 43 | |
| 44 /** | |
| 45 * A completer that will be completed when code completion results have been | |
| 46 * received from the server. | |
| 47 */ | |
| 48 Completer completionReceived; | |
| 49 | |
| 50 /** | |
| 51 * Initialize a newly created test. | |
| 52 */ | |
| 53 SimpleTest(); | |
| 54 | |
| 55 @override | |
| 56 Future oneTimeSetUp() { | |
| 57 return super.oneTimeSetUp().then((_) { | |
| 58 mainFilePath = sourcePath('test.dart'); | |
| 59 originalContent = r''' | |
| 60 class C { | |
| 61 m() { | |
| 62 return 0; | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 f(C c) { | |
| 67 return c; | |
| 68 } | |
| 69 '''; | |
| 70 cursorOffset = originalContent.indexOf('c;') + 1; | |
| 71 writeFile(mainFilePath, originalContent); | |
| 72 }); | |
| 73 } | |
| 74 | |
| 75 @override | |
| 76 Future setUp() { | |
| 77 completionReceived = new Completer(); | |
| 78 onCompletionResults.listen((_) { | |
| 79 // We only care about the time to the first response. | |
| 80 if (!completionReceived.isCompleted) { | |
| 81 completionReceived.complete(); | |
| 82 } | |
| 83 }); | |
| 84 int separatorIndex = mainFilePath.lastIndexOf('/'); | |
|
Paul Berry
2014/10/03 16:58:35
I think this will be wrong on Windows. Instead us
Brian Wilkerson
2014/10/03 17:17:37
Done
| |
| 85 String mainDirectory = mainFilePath.substring(0, separatorIndex); | |
|
scheglov
2014/10/03 16:46:14
We could use package:path for this.
Brian Wilkerson
2014/10/03 17:17:37
Done
| |
| 86 sendAnalysisSetAnalysisRoots([mainDirectory], []); | |
| 87 sendAnalysisUpdateContent({ | |
| 88 mainFilePath: { | |
| 89 'type': 'add', | |
| 90 'content': originalContent | |
| 91 } | |
| 92 }); | |
| 93 return new Future.value(); | |
| 94 } | |
| 95 | |
| 96 @override | |
| 97 Future perform() { | |
| 98 sendAnalysisUpdateContent({ | |
| 99 mainFilePath: { | |
| 100 'type': 'change', | |
| 101 'edits': [{ | |
| 102 'offset': cursorOffset, | |
| 103 'length': 0, | |
| 104 'replacement': '.' | |
| 105 }] | |
| 106 } | |
| 107 }); | |
| 108 sendCompletionGetSuggestions(mainFilePath, cursorOffset + 1); | |
| 109 return completionReceived.future; | |
| 110 } | |
| 111 | |
| 112 @override | |
| 113 Future tearDown() { | |
| 114 sendAnalysisSetAnalysisRoots([], []); | |
| 115 return new Future.value(); | |
| 116 } | |
| 117 } | |
| OLD | NEW |