mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Update speed test to do multiple parses in a pass.
This commit is contained in:
parent
5a66875392
commit
3d0734f6ca
1 changed files with 22 additions and 7 deletions
|
@ -10,11 +10,12 @@ import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
import org.eclipse.cdt.core.parser.IParser;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
|
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
|
||||||
|
|
||||||
// A test that just calculates the speed of the parser
|
// A test that just calculates the speed of the parser
|
||||||
// Eventually, we'll peg a max time and fail the test if it exceeds it
|
// Eventually, we'll peg a max time and fail the test if it exceeds it
|
||||||
|
@ -22,13 +23,17 @@ public class SpeedTest extends TestCase {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
new SpeedTest().test();
|
new SpeedTest().runTest(1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
runTest(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTest(int n) throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"#include <windows.h>\n" +
|
"#include <windows.h>\n" +
|
||||||
"#include <stdio.h>\n" +
|
"#include <stdio.h>\n" +
|
||||||
|
@ -36,15 +41,24 @@ public class SpeedTest extends TestCase {
|
||||||
|
|
||||||
CodeReader reader = new CodeReader(code.toCharArray());
|
CodeReader reader = new CodeReader(code.toCharArray());
|
||||||
IScannerInfo info = mingwScannerInfo(false);
|
IScannerInfo info = mingwScannerInfo(false);
|
||||||
//IScannerInfo info = msvcScannerInfo(quick);
|
//IScannerInfo info = msvcScannerInfo(false);
|
||||||
testParse(reader, false, info, ParserLanguage.CPP);
|
long totalTime = 0;
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
long time = testParse(reader, false, info, ParserLanguage.CPP);
|
||||||
|
if (i > 0)
|
||||||
|
totalTime += time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
System.out.println("Average Time: " + (totalTime / (n - 1)) + " millisecs");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param path
|
* @param path
|
||||||
* @param quick TODO
|
* @param quick TODO
|
||||||
*/
|
*/
|
||||||
protected void testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
protected long testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
||||||
IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
||||||
IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null);
|
IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null);
|
||||||
|
@ -54,9 +68,10 @@ public class SpeedTest extends TestCase {
|
||||||
totalTime = System.currentTimeMillis() - startTime;
|
totalTime = System.currentTimeMillis() - startTime;
|
||||||
System.out.println( "Resulting parse took " + totalTime + " millisecs " +
|
System.out.println( "Resulting parse took " + totalTime + " millisecs " +
|
||||||
scanner.getCount() + " tokens");
|
scanner.getCount() + " tokens");
|
||||||
|
return totalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final QuickParseCallback CALLBACK = new QuickParseCallback();
|
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param quick
|
* @param quick
|
||||||
|
|
Loading…
Add table
Reference in a new issue