⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serqlperftest.java

📁 这是外国一个开源推理机
💻 JAVA
字号:
package org.openrdf.sesame.query.serql;import java.net.URL;import org.openrdf.sesame.constants.QueryLanguage;import org.openrdf.sesame.query.QueryResultsTable;import org.openrdf.sesame.repository.remote.HTTPRepository;import org.openrdf.sesame.repository.remote.HTTPService;/** * Performance test that sends SeRQL queries to a Sesame server and * measures the average time it takes to send a query and parse the * query results. */public class SeRQLPerfTest {/*--------------------+| Constants           |+--------------------*/	public static final String SERVER_URL = "http://localhost/sesame/";	//public static final String REPOSITORY = "mem-rdf-db";	//public static final String REPOSITORY = "mem-rdfs-db";	public static final String REPOSITORY = "rdf-mysql-db";	//public static final String REPOSITORY = "rdfs-mysql-db";	// test query 1 (1 result)	public static final String QUERY1 =			"select Country, Name " +			"from {Country} <ciafb:Name> {Name}; " +			               "<ciafb:Map_references> {\"Africa\"}; " +			               "<ciafb:Natural_resources> {\"oil\"} " +			"using namespace " +			"ciafb = <!http://www.cia.gov/cia/publications/factbook#>";	// test query 2 (12 results)	public static final String QUERY2 =			"select Country, Name " +			"from {Country} <ciafb:Name> {Name}; " +			               "<ciafb:Map_references> {\"Africa\"}; " +			               "<ciafb:Natural_resources> {\"petroleum\"} " +			"using namespace " +			"ciafb = <!http://www.cia.gov/cia/publications/factbook#>";	// test query 3 (247 results)	public static final String QUERY3 =			"select Country, Name, NatRes " +			"from {Country} <ciafb:Name> {Name}; " +			               "<ciafb:Map_references> {\"Africa\"}; " +			               "<ciafb:Natural_resources> {NatRes} " +			"using namespace " +			"ciafb = <!http://www.cia.gov/cia/publications/factbook#>";	// test query 4 (1 result)	public static final String QUERY4 =			"select Country, Name " +			"from {Country} <ciafb:Name> {Name}; " +			               "<ciafb:Map_references> {\"Africa\"}; " +			               "<ciafb:Area_comparative> {\"slightly larger than Georgia\"}; " +			               "<ciafb:Natural_resources> {\"petroleum\"}; " +			               "<ciafb:Natural_resources> {\"iron ore\"}; " +			               "<ciafb:Government_type> {\"republic\"}; " +			               "<ciafb:Fiscal_year> {\"calendar year\"} " +			"using namespace " +			"ciafb = <!http://www.cia.gov/cia/publications/factbook#>";/*--------------------+| Methods             |+--------------------*/	public static void main(String[] args) {		try {			HTTPService service = new HTTPService(new URL(SERVER_URL));			HTTPRepository repository = (HTTPRepository)service.getRepository(REPOSITORY);			// Dummy runs to ensure classes are loaded, etc.			System.out.println("Repository: " + REPOSITORY);			System.out.println("Performing dummy runs");			_timeQuery(repository, QUERY1, 10);			_timeQuery(repository, QUERY2, 10);			_timeQuery(repository, QUERY3, 10);			_timeQuery(repository, QUERY4, 10);			// Give JVM time to optimize stuff			System.out.println("Waiting 2 seconds");			Thread.sleep(2000);			System.out.println("Starting measurements");			float avgTime = _timeQuery(repository, QUERY1, 250);			System.out.println("avg time for query 1: " + avgTime + " ms");			avgTime = _timeQuery(repository, QUERY2, 250);			System.out.println("avg time for query 2: " + avgTime + " ms");			avgTime = _timeQuery(repository, QUERY3, 250);			System.out.println("avg time for query 3: " + avgTime + " ms");			avgTime = _timeQuery(repository, QUERY4, 250);			System.out.println("avg time for query 4: " + avgTime + " ms");		}		catch (Exception e) {			e.printStackTrace();		}	}	private static float _timeQuery(HTTPRepository repository, String query, int iterationCount)		throws Exception	{		QueryResultsTable queryResult = null;		long startTime = System.currentTimeMillis();		for (int i = 0; i < iterationCount; i++) {			queryResult = repository.performTableQuery(QueryLanguage.SERQL, query);		}		long endTime = System.currentTimeMillis();		return (endTime - startTime) / (float)iterationCount;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -