📄 rdfsourcebmtestb.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 java.util.List;import org.openrdf.sesame.sail.RdfSource;import org.openrdf.sesame.sail.test.benchmark.util.BMUtil;/** * Tests performance of one method of org.openrdf.sesame.sail.RdfSource. * * DOME * * @author Peter van 't Hof. * @version %I%, %G% */public abstract class RdfSourceBMTestB extends SailBMTestA {/*----------+| Variables |+----------*/ // RdfSource to test performance of. protected RdfSource _rdfSource; // Time benchmark test A costs. protected long _totalTimeA; // Number of times call A is made to the repository. protected int _callsA; // Time test B costs. protected long _totalTimeB; // Number of times call B is made to the repository. protected int _callsB; // Time one individual call A takes. protected long _timeA; // Time one individual call B takes. protected long _timeB;/*-------------+| Constructors |+-------------*/ /** * Creates a new benchmark test which tests one method of * org.openrdf.sesame.sail.RdfSource. * * @param name Name of test. * @param rdfSource RdfSource to test. */ public RdfSourceBMTestB(String name, RdfSource rdfSource) { super(name, rdfSource); _rdfSource = rdfSource; _totalTimeA = 0; _timeA = 0; _callsA = 0; _totalTimeB = 0; _timeB = 0; _callsB = 0; }/*--------+| Methods |+--------*/ /** * Tests performance of one method of org.openrdf.sesame.sail.RdfSource. * * @throws Exception If Exception was thrown. */ public void test() throws Exception { // Continue until minimum number of calls reached. if (_callsA < _minimum) { _testA(); } if (_callsB < _minimum) { _testB(); } /* If both calls A and B are greater than or equal to minimum calls test * is done. If one of them is equal to zero repository does not provide * sufficient variables for test. */ if ((_callsA >= _minimum || _callsA == 0) && (_callsB >= _minimum || _callsB == 0)) { _testDone = true; } } protected void _testA() throws Exception {} protected void _testB() throws Exception {} public long getTime() { // Update time. _totalTime = _getTimeA() + _getTimeB(); return _totalTime; } public int getCalls() { // Update calls. _calls = _getCallsA() + _getCallsB(); return _calls; } protected long _getTimeA() { return _totalTimeA; } protected long _getTimeB() { return _totalTimeB; } protected int _getCallsA() { return _callsA; } protected int _getCallsB() { return _callsB; } // Starts time A. protected void _startA() { _timeA = System.currentTimeMillis(); } protected void _stopA() { _stopA(1); } // Stops time A and increases number of calls A by calls. protected void _stopA(int calls) { _totalTimeA += System.currentTimeMillis() - _timeA; _callsA += calls; } // Starts time B. protected void _startB() { _timeB = System.currentTimeMillis(); } protected void _stopB() { _stopB(1); } // Stops time A and increases number of calls B by calls. protected void _stopB(int calls) { _totalTimeB += System.currentTimeMillis() - _timeB; _callsB += calls; } /* Computes average between timeA and timeB. If timeA is equal to zero, no * call to the repository was made, timeA cannot be part of the average and * timeB is returned or vice versa. */ protected double _averageX(double timeA, double timeB) { if (timeA == 0) { return timeB; } if (timeB == 0) { return timeA; } return _average((long)((timeA + timeB)*100), 200); } protected List _cutDown(List list, int size) { return BMUtil.cutDown(list, size); } protected String _toString(String A, String B) { // Update time and calls. getTime(); getCalls(); double averageA = _average(_totalTimeA, _callsA); double averageB = _average(_totalTimeB, _callsB); String result = _appendTabs(_name.toUpperCase()) + "|Average(calls) in ms\n" + "----------------+--------\n" + _appendTabs(A) + "|" + _x(averageA) + "(" + _callsA + ")\n" + _appendTabs(B) + "|" + _x(averageB) + "(" + _callsB + ")\n" + "Total\t\t|" + _x(_averageX(averageA, averageB)) + "(" + _calls + ")"; return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -