📄 rdfschemasourcebmtestc.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.sesame.sail.RdfSchemaSource;/** * Tests performance of one method of org.openrdf.sesame.sail.RdfSchemaSource. * * DOME * * @author Peter van 't Hof. * @version %I%, %G% */public abstract class RdfSchemaSourceBMTestC extends RdfSourceBMTestB {/*----------+| Variables |+----------*/ // RdfSchemaSource to test performance of. protected RdfSchemaSource _rdfSchemaSource; // Time benchmark test A1 costs. protected long _totalTimeA1; // Number of times call A1 is made to the repository. protected int _callsA1; // Time test A2 costs. protected long _totalTimeA2; // Number of times call A2 is made to the repository. protected int _callsA2; // Time test B1 costs. protected long _totalTimeB1; // Number of times call B1 is made to the repository. protected int _callsB1; // Time test B2 costs. protected long _totalTimeB2; // Number of times call B2 is made to the repository. protected int _callsB2; // Time one individual call A1 takes. protected long _timeA1; // Time one individual call A2 takes. protected long _timeA2; // Time one individual call B1 takes. protected long _timeB1; // Time one individual call B2 takes. protected long _timeB2;/*-------------+| Constructors |+-------------*/ /** * Creates a new benchmark test which tests one method of * org.openrdf.sesame.sail.RdfSchemaSource. * * @param name Name of test. * @param rdfSchemaSource RdfSchemaSource to test. */ public RdfSchemaSourceBMTestC(String name, RdfSchemaSource rdfSchemaSource) { super(name, rdfSchemaSource); _rdfSchemaSource = rdfSchemaSource; _totalTimeA1 = 0; _timeA1 = 0; _callsA1 = 0; _totalTimeA2 = 0; _timeA2 = 0; _callsA2 = 0; _totalTimeB1 = 0; _timeB1 = 0; _callsB1 = 0; _totalTimeB2 = 0; _timeB2 = 0; _callsB2 = 0; }/*--------+| Methods |+--------*/ /** * Tests performance of one method of * org.openrdf.sesame.sail.RdfSchemaSource. */ public void test() { // Continue until minimum number of calls reached. if (_callsA1 < _minimum) { _testA1(); } if (_callsA2 < _minimum) { _testA2(); } if (_callsB1 < _minimum) { _testB1(); } if (_callsB2 < _minimum) { _testB2(); } /* If calls A and B of type one and two 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 ((_callsA1 >= _minimum || _callsA1 == 0) && (_callsA2 >= _minimum || _callsA2 == 0) && (_callsB1 >= _minimum || _callsB1 == 0) && (_callsB2 >= _minimum || _callsB2 == 0)) _testDone = true; } protected void _testA1() {} protected void _testA2() {} protected void _testB1() {} protected void _testB2() {} protected long _getTimeA() { // Update timeA. _totalTimeA = _totalTimeA1 + _totalTimeA2; return _totalTimeA; } protected long _getTimeB() { // Update time B. _totalTimeB = _totalTimeB1 + _totalTimeB2; return _totalTimeB; } protected int _getCallsA() { // Update calls A. _callsA = _callsA1 + _callsA2; return _callsA; } protected int _getCallsB() { // Update calls B. _callsB = _callsB1 + _callsB2; return _callsB; } protected void _startA1() { _startA(true); } protected void _stopA1() { _stopA(true); } protected void _startA2() { _startA(false); } protected void _stopA2() { _stopA(false); } // Starts time A1 or A2 depending on type. protected void _startA(boolean type) { if (type) { _timeA1 = System.currentTimeMillis(); } else { _timeA2 = System.currentTimeMillis(); } } protected void _stopA(boolean type) { _stopA(type, 1); } /* Stops time A1 or A2 and increases number of calls A1 or A2 by calls * depending on type. */ protected void _stopA(boolean type, int calls) { if (type) { _totalTimeA1 += System.currentTimeMillis() - _timeA1; _callsA1 += calls; } else { _totalTimeA2 += System.currentTimeMillis() - _timeA2; _callsA2 += calls; } } protected void _startB1() { _startB(false); } // Starts time B1 or B2 depending on type. protected void _startB(boolean type) { if (type) { _timeB1 = System.currentTimeMillis(); } else { _timeB2 = System.currentTimeMillis(); } } protected void _stopB1() { _stopB(false); } protected void _stopB(boolean type) { _stopB(type, 1); } /* Stops time B1 or B2 and increases number of calls B1 or B2 by calls * depending on type. */ protected void _stopB(boolean type, int calls) { if (type) { _totalTimeB1 += System.currentTimeMillis() - _timeB1; _callsB1 += calls; } else { _totalTimeB2 += System.currentTimeMillis() - _timeB2; _callsB2 += calls; } } protected String _toString(String A, String B, String one, String two) { // Update all time and calls variables. getTime(); getCalls(); long time1 = _totalTimeA1 + _totalTimeB1; long time2 = _totalTimeA2 + _totalTimeB2; int calls1 = _callsA1 + _callsB1; int calls2 = _callsA2 + _callsB2; double averageA1 = _average(_totalTimeA1, _callsA1); double averageA2 = _average(_totalTimeA2, _callsA2); double averageB1 = _average(_totalTimeB1, _callsB1); double averageB2 = _average(_totalTimeB2, _callsB2); double averageA = _averageX(averageA1, averageA2); double averageB = _averageX(averageB1, averageB2); double average1 = _averageX(averageA1, averageB1); double average2 = _averageX(averageA2, averageB2); double average = _averageX(averageA, averageB); String toString = _appendTabs(_name.toUpperCase()) + "|Average(calls) in ms\n" + "\t\t|" + _appendTabs(one) + _appendTabs(two) + "Total\n" + "----------------+----------------------------------------\n" + _appendTabs(A) + "|" + _x(averageA1) + "(" + _callsA1 + ")\t" + _x(averageA2) + "(" + _callsA2 + ")\t" + _x(averageA) + "(" + _callsA + ")\n" + _appendTabs(B) + "|" + _x(averageB1) + "(" + _callsB1 + ")\t" + _x(averageB2) + "(" + _callsB2 + ")\t" + _x(averageB) + "(" + _callsB + ")\n" + "Total\t\t|" + _x(average1) + "(" + calls1 + ")\t" + _x(average2) + "(" + calls2 + ")\t" + _x(average) + "(" + _calls + ")"; return toString; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -