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

📄 sailbmtesta.java

📁 这是外国一个开源推理机
💻 JAVA
字号:
/*  Sesame - Storage and Querying architecture for RDF and RDF Schema *  Copyright (C) 2001-2005 Aduna * *  Contact:  *  	Aduna *  	Prinses Julianaplein 14 b *  	3817 CS Amersfoort *  	The Netherlands *  	tel. +33 (0)33 465 99 87 *  	fax. +33 (0)33 465 99 87 * *  	http://aduna.biz/ *  	http://www.openrdf.org/ *   *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.openrdf.sesame.sail.test.benchmark.tests;import org.openrdf.model.BNode;import org.openrdf.model.Literal;import org.openrdf.model.Resource;import org.openrdf.model.Statement;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.sesame.sail.Sail;import org.openrdf.sesame.sail.test.benchmark.util.BMUtil;/** * Tests performance of one method of org.openrdf.sesame.sail.Sail. * * DOME *  * @author Peter van 't Hof. * @version %I%, %G% */public abstract class SailBMTestA {/*----------+| Variables |+----------*/	// Sail to test performance of.	protected Sail _sail;		// Name of benchmark test.	protected String _name;	// Time test takes.	protected long _totalTime;	// Number of times test makes call.	protected int _calls;		// Boolean indicating if test is done.	protected boolean _testDone;	// Minimum number of calls every test must make.	protected static final int _minimum = 100;	// Maximum time test can take in millisseconds.	protected static final int _maxTime = 54000000;	// Boolean indicating if test needs a pool.	protected boolean _needsPool;	// Time one individual call takes.	protected long _time;/*-------------+| Constructors |+-------------*/	/**	 * Creates a new benchmark test which tests one method of	 * org.openrdf.sesame.sail.Sail.	 *	 * @param name Name of test.	 * @param sail Sail to test.	 */	public SailBMTestA(String name, Sail sail) {		_name = name;		_sail = sail;		_totalTime = 0;		_calls = 0;		_testDone = false;		_needsPool = false;		_time = 0;	}/*--------+| Methods |+--------*/	/**	 * Tests performance of one method of org.openrdf.sesame.sail.Sail.	 *	 * @throws Exception If an Exception is thrown.	 */	public void test() 		throws Exception {		// Continue until minimum number of calls reached.		if (_calls < _minimum) {			_test();		}		/* If calls is greater than or equal to minimum calls test is done. If		 * calls is equal to zero repository does not provide sufficient		 * variables for test.		 */		if (_calls >= _minimum || _calls == 0) {			_testDone = true;		}	}	protected void _test()		throws Exception {}	/**	 * Gets time benchmark test took.	 *	 * @return Time test took.	 */	public long getTime() {		return _totalTime;	}	/**	 * Gets calls benchmark test made.	 *	 * @return Calls test made.	 */	public int getCalls() {		return _calls;	}	/**	 * Returns boolean indicating if benchmark test is done.	 *	 * @return True if test is done; false otherwise.	 */	public boolean testDone() {		return _testDone;	}	/**	 * Returns boolean indicating if benchmark test needs a pool.	 *	 * @return True if test needs pool; false otherwise.	 */	public boolean needsPool() {		return _needsPool;	}		/**	 * Returns benchmark test results.	 *	 * @return Test results.	 */	public String toString() {		String result = 			_appendTabs(_name.toUpperCase()) + "|Average(calls) in ms\n" +			"----------------+--------\n" +			"Total\t\t|" + _x(_average(getTime(), getCalls())) + "(" + 				getCalls() + ")";				return result;	}		// Appends tabs to String until String has length sixteen.	protected String _appendTabs(String string) {		int length = string.length();		if (length < 8) {			string += "\t";		}		if (length < 16) {			string += "\t";		}		return string;	}	// Starts time.	protected void _start() {		_time = System.currentTimeMillis();	}	// Stops time and increases number of calls by one.	protected void _stop() {		_totalTime += System.currentTimeMillis() - _time;				_calls++;	}	/* Computes average between time and number of calls and rounds outcome to a	 * scale of two.	 */	protected double _average(long time, int calls) {		if (calls == 0) {			return 0;		}		else {			return (double)(int)(((double)time/calls)*100 +0.5)/100;		}	}	// Simulates real world use of Value.	protected void _simulateUsage(Value value) {		if (value instanceof Resource) {			_simulateUsage((Resource)value);		}		else {				Literal literal = (Literal)value;			literal.getLanguage();			literal.getLabel();		}				}	// Simulates real world usage of Resource. 	protected void _simulateUsage(Resource resource) {		if (resource instanceof URI) {			((URI)resource).getNamespace();			((URI)resource).getLocalName();		}		else {			((BNode)resource).getID();		}	}	// Simulates real world use of Statement.	protected void _simulateUsage(Statement statement) {		_simulateUsage(statement.getSubject());		_simulateUsage(statement.getPredicate());		_simulateUsage(statement.getObject());	}	/* Rounds a double to a significance of two.	 *	 * DOME explain method body, if you can.	 */	protected double _round(double input) {		double result = 0;		if (input != 0) {			double log = Math.log(input)/Math.log(10);			double pow = Math.pow(10, Math.floor(log) -1);			double d = 0;			long l = 0;			if (log >= 1) {				d = input/pow;				l  = Math.round(d);				result = l * pow;				}			else {				double e = 1/pow;				d = input * e;				l = Math.round(d);				result = l/e;			}		}		return result;	}	/* Rounds double to a significance of two, converts double to String, removes	 * ".0" and appends tab if length of String representation of double is	 * smaller than 7.	 *	 * DOME come up with a meaningful name, if any.	 */	protected String _x(double d) {		String result = String.valueOf(_round(d));				// Remove ".0"		if (result.endsWith(".0")) {			result = result.substring(0, result.length() - 2);		}		// Append tab if length of String < 7.		if (result.length() < 7) {			result += "\t";		}		return result;	}	protected void _status(String status) {		BMUtil.status(status);	}	protected void _error(String error) {		BMUtil.error(error);	}	protected void _exit(String error) {		BMUtil.exit(error);	}}

⌨️ 快捷键说明

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