Package com.ibm.icu.dev.test.perf
Class PerfTest
- java.lang.Object
-
- com.ibm.icu.dev.test.perf.PerfTest
-
- Direct Known Subclasses:
BreakIteratorPerformanceTest
,ConverterPerformanceTest
,DateFormatPerformanceTest
,DecimalFormatPerformanceTest
,NormalizerPerformanceTest
,RBBIPerf
,ResourceBundlePerf
,ServiceObjectCreationPerf
,UCharacterPerf
,UnicodeSetPerf
public abstract class PerfTest extends java.lang.Object
Base class for performance testing framework. To use, the subclass can simply define one or more instance methods with names beginning with "test" (case ignored). The prototype of the method is PerfTest.Function testTheName() The actual performance test will execute on the returned Command object (refer to Command Pattern). To call a test from command line, the 'test' prefix of the test method name can be ignored/removed. In addition, the subclass should define a main() method that calls PerfTest.run() as defined here. If the subclasses uses any command line arguments (beyond those handled automatically by this class) then it should override PerfTest.setup() to handle its arguments. If the subclasses needs more sophisticated management for controlling finding/calling test method, it can replace the default implementation for PerfTest.testProvider before calling PerfTest.run(). Example invocation: java -cp classes -verbose:gc com.ibm.icu.dev.test.perf.UnicodeSetPerf --gc --passes 4 --iterations 100 UnicodeSetAdd [[:l:][:c:]] Example output: [GC 511K->192K(1984K), 0.0086170 secs] [GC 704K->353K(1984K), 0.0059619 secs] [Full GC 618K->371K(1984K), 0.0242779 secs] [Full GC 371K->371K(1984K), 0.0228649 secs] = testUnicodeSetAdd begin 100 = testUnicodeSetAdd end 11977 1109044 = testUnicodeSetAdd begin 100 = testUnicodeSetAdd end 12047 1109044 = testUnicodeSetAdd begin 100 = testUnicodeSetAdd end 11987 1109044 = testUnicodeSetAdd begin 100 = testUnicodeSetAdd end 11978 1109044 The [] lines are emitted by the JVM as a result of the -verbose:gc switch. Lines beginning with '=' are emitted by PerfTest: = testUnicodeSetAdd begin 100 A 'begin' statement contains the name of the setup method, which determines what test function is measures, and the number of iterations that will be times. = testUnicodeSetAdd end 12047 1109044 An 'end' statement gives the name of the setup method again, and then two integers. The first is the total elapsed time in milliseconds, and the second is the number of events per iteration. In this example, the time per event is 12047 / (100 * 1109044) or 108.6 ns/event. Raw times are given as integer ms, because this is what the system measures.- Since:
- ICU 2.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PerfTest.BOMFreeReader
static class
PerfTest.Function
Subclasses of PerfTest will need to create subclasses of Function that define a call() method which contains the code to be timed.private class
PerfTest.FunctionRunner
(package private) static interface
PerfTest.TestCmdProvider
(package private) static class
PerfTest.TestPrefixProvider
Treat all method beginning with 'test' prefix (ignoring case) for given object as the test methods.static class
PerfTest.UsageException
Exception indicating a usage error.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
action
(package private) static int
ACTION
protected boolean
bulk_mode
(package private) static int
BULK_MODE
protected boolean
doPriorGC
protected int
duration
(package private) static int
DURATION
protected java.lang.String
encoding
(package private) static int
ENCODING
(package private) static int
FILE_NAME
protected java.lang.String
fileName
(package private) static int
GARBAGE_COLLECT
(package private) static int
HELP1
These must be kept in sync with getOptions().(package private) static int
HELP2
protected int
iterations
(package private) static int
ITERATIONS
protected boolean
line_mode
(package private) static int
LINE_MODE
(package private) static int
LIST
protected java.util.Locale
locale
(package private) static int
LOCALE
protected int
passes
(package private) static int
PASSES
protected java.lang.String
sourceDir
(package private) static int
SOURCEDIR
(package private) static int
TEST_NAME
protected java.lang.String
testName
protected PerfTest.TestCmdProvider
testProvider
protected int
threads
(package private) static int
THREADS
protected int
time
(package private) static int
TIME
protected boolean
uselen
(package private) static int
USELEN
protected boolean
verbose
(package private) static int
VERBOSE
-
Constructor Summary
Constructors Modifier Constructor Description protected
PerfTest()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
gc()
Invoke the runtime's garbage collection procedure repeatedly until the amount of free memory stabilizes to within 10%.private long
getIteration(java.lang.String methName, PerfTest.Function fn)
Translate '-t time' to iterations (or just return '-i iteration')(package private) UOption[]
getOptions()
private java.util.Set
parseOptions(java.lang.String[] args)
private long
performLoops(PerfTest.Function function, long loops)
java.lang.String
readDataLine(java.io.BufferedReader br)
protected java.lang.String[]
readLines(java.lang.String filename, java.lang.String srcEncoding, boolean bulkMode)
static byte[]
readToEOS(java.io.InputStream stream)
static char[]
readToEOS(java.io.Reader reader)
protected void
run(java.lang.String[] args)
Subclasses should call this method in their main().protected void
setup(java.lang.String[] args)
Framework method.
-
-
-
Field Detail
-
verbose
protected boolean verbose
-
sourceDir
protected java.lang.String sourceDir
-
fileName
protected java.lang.String fileName
-
encoding
protected java.lang.String encoding
-
testName
protected java.lang.String testName
-
uselen
protected boolean uselen
-
iterations
protected int iterations
-
passes
protected int passes
-
time
protected int time
-
line_mode
protected boolean line_mode
-
bulk_mode
protected boolean bulk_mode
-
locale
protected java.util.Locale locale
-
doPriorGC
protected boolean doPriorGC
-
threads
protected int threads
-
duration
protected int duration
-
action
protected boolean action
-
testProvider
protected PerfTest.TestCmdProvider testProvider
-
HELP1
static final int HELP1
These must be kept in sync with getOptions().- See Also:
- Constant Field Values
-
HELP2
static final int HELP2
- See Also:
- Constant Field Values
-
VERBOSE
static final int VERBOSE
- See Also:
- Constant Field Values
-
SOURCEDIR
static final int SOURCEDIR
- See Also:
- Constant Field Values
-
ENCODING
static final int ENCODING
- See Also:
- Constant Field Values
-
USELEN
static final int USELEN
- See Also:
- Constant Field Values
-
FILE_NAME
static final int FILE_NAME
- See Also:
- Constant Field Values
-
PASSES
static final int PASSES
- See Also:
- Constant Field Values
-
ITERATIONS
static final int ITERATIONS
- See Also:
- Constant Field Values
-
TIME
static final int TIME
- See Also:
- Constant Field Values
-
LINE_MODE
static final int LINE_MODE
- See Also:
- Constant Field Values
-
BULK_MODE
static final int BULK_MODE
- See Also:
- Constant Field Values
-
LOCALE
static final int LOCALE
- See Also:
- Constant Field Values
-
TEST_NAME
static final int TEST_NAME
- See Also:
- Constant Field Values
-
THREADS
static final int THREADS
- See Also:
- Constant Field Values
-
DURATION
static final int DURATION
- See Also:
- Constant Field Values
-
ACTION
static final int ACTION
- See Also:
- Constant Field Values
-
GARBAGE_COLLECT
static final int GARBAGE_COLLECT
- See Also:
- Constant Field Values
-
LIST
static final int LIST
- See Also:
- Constant Field Values
-
-
Method Detail
-
setup
protected void setup(java.lang.String[] args)
Framework method. Default implementation does not parse any extra arguments. Subclasses may override this to parse extra arguments. Subclass implementations should NOT call the base class implementation.
-
getOptions
UOption[] getOptions()
-
run
protected final void run(java.lang.String[] args) throws java.lang.Exception
Subclasses should call this method in their main(). run() will in turn call setup() with any arguments it does not parse. This method parses the command line and runs the tests given on the command line, with the given parameters. See the class description for details.- Throws:
java.lang.Exception
-
parseOptions
private java.util.Set parseOptions(java.lang.String[] args) throws PerfTest.UsageException
- Parameters:
args
-- Returns:
- the method list to call
- Throws:
PerfTest.UsageException
-
getIteration
private long getIteration(java.lang.String methName, PerfTest.Function fn) throws java.lang.InterruptedException
Translate '-t time' to iterations (or just return '-i iteration')- Parameters:
meth
-fn
-- Returns:
- rt
- Throws:
java.lang.InterruptedException
-
performLoops
private long performLoops(PerfTest.Function function, long loops) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
gc
protected void gc()
Invoke the runtime's garbage collection procedure repeatedly until the amount of free memory stabilizes to within 10%.
-
readToEOS
public static char[] readToEOS(java.io.Reader reader)
-
readToEOS
public static byte[] readToEOS(java.io.InputStream stream)
-
readLines
protected java.lang.String[] readLines(java.lang.String filename, java.lang.String srcEncoding, boolean bulkMode)
-
readDataLine
public java.lang.String readDataLine(java.io.BufferedReader br) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-