1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +02:00

Updated the SpeedTest to allow for run time selection of configs and to support

the new ScannerSpeedTest which just tests the scanner.
This commit is contained in:
Doug Schaefer 2004-06-09 11:43:21 +00:00
parent 0e0f456412
commit e1d46bbeed
2 changed files with 95 additions and 8 deletions

View file

@ -0,0 +1,80 @@
/*
* Created on Jun 8, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.cdt.core.parser.tests;
import java.util.Collections;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IScanner;
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.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
/**
* @author Doug Schaefer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ScannerSpeedTest extends SpeedTest {
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
public void test() throws Exception {
runTest(10);
}
private void runTest(int n) throws Exception {
String code =
"#include <windows.h>\n" +
"#include <stdio.h>\n" +
"#include <iostream>\n";
CodeReader reader = new CodeReader(code.toCharArray());
IScannerInfo info = getScannerInfo(false);
long totalTime = 0;
for (int i = 0; i < n; ++i) {
long time = testScan(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 quick TODO
*/
protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
long startTime = System.currentTimeMillis();
try {
while (true) {
try {
if (scanner.nextToken() == null)
break;
} catch (ScannerException e) {
}
}
} catch (EndOfFileException e2) {
}
long totalTime = System.currentTimeMillis() - startTime;
System.out.println( "Resulting scan took " + totalTime + " millisecs " +
scanner.getCount() + " tokens");
return totalTime;
}
}

View file

@ -40,8 +40,7 @@ public class SpeedTest extends TestCase {
"#include <iostream>\n";
CodeReader reader = new CodeReader(code.toCharArray());
IScannerInfo info = mingwScannerInfo(false);
//IScannerInfo info = msvcScannerInfo(false);
IScannerInfo info = getScannerInfo(false);
long totalTime = 0;
for (int i = 0; i < n; ++i) {
long time = testParse(reader, false, info, ParserLanguage.CPP);
@ -73,11 +72,19 @@ public class SpeedTest extends TestCase {
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
/**
* @param quick
* @return
*/
protected IScannerInfo msvcScannerInfo(boolean quick) {
protected IScannerInfo getScannerInfo(boolean quick) {
if (quick)
return new ScannerInfo();
String config = System.getProperty("speedTest.config");
if (config != null && config.equals("msvc"))
return msvcScannerInfo(false);
else
return mingwScannerInfo(false);
}
private IScannerInfo msvcScannerInfo(boolean quick) {
if( quick )
return new ScannerInfo();
Map definitions = new Hashtable();
@ -90,7 +97,7 @@ public class SpeedTest extends TestCase {
return new ScannerInfo( definitions, includePaths );
}
protected IScannerInfo mingwScannerInfo(boolean quick) {
private IScannerInfo mingwScannerInfo(boolean quick) {
// TODO It would be easier and more flexible if we used discovery for this
if( quick )
return new ScannerInfo();