Class PerfTest
- Direct Known Subclasses:
BreakIteratorPerformanceTest
,ConverterPerformanceTest
,DateFormatPerformanceTest
,DecimalFormatPerformanceTest
,NormalizerPerformanceTest
,RBBIPerf
,ResourceBundlePerf
,ServiceObjectCreationPerf
,UCharacterPerf
,UnicodeSetPerf
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 use any command line arguments (beyond those handled automatically by this class) then it should override PerfTest.setup() to handle its arguments. If the subclasses need 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 ClassesModifier and TypeClassDescriptionstatic class
static class
Subclasses of PerfTest will need to create subclasses of Function that define a call() method which contains the code to be timed.private class
(package private) static interface
(package private) static class
Treat all method beginning with 'test' prefix (ignoring case) for given object as the test methods.static class
Exception indicating a usage error. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
(package private) static final String
protected boolean
(package private) static final String
protected boolean
protected int
(package private) static final String
protected String
(package private) static final String
(package private) static final String
protected String
(package private) static final String
(package private) static final String
These are to be used in Options.protected int
(package private) static final String
protected boolean
(package private) static final String
(package private) static final String
protected Locale
(package private) static final String
(package private) static final org.apache.commons.cli.Options
protected int
(package private) static final String
protected String
(package private) static final String
(package private) static final String
protected String
protected PerfTest.TestCmdProvider
protected int
(package private) static final String
protected int
(package private) static final String
protected boolean
(package private) static final String
protected boolean
(package private) static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
gc()
Invoke the runtime's garbage collection procedure repeatedly until the amount of free memory stabilizes to within 10%.private long
getIteration
(String methName, PerfTest.Function fn) Translate '-t time' to iterations (or just return '-i iteration')(package private) org.apache.commons.cli.Options
parseOptions
(String[] args) private long
performLoops
(PerfTest.Function function, long loops) protected String[]
static byte[]
readToEOS
(InputStream stream) static char[]
protected final void
Subclasses should call this method in their main().protected void
Framework method.
-
Field Details
-
verbose
protected boolean verbose -
sourceDir
-
fileName
-
encoding
-
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
-
doPriorGC
protected boolean doPriorGC -
threads
protected int threads -
duration
protected int duration -
action
protected boolean action -
testProvider
-
HELP
These are to be used in Options.- See Also:
-
VERBOSE
- See Also:
-
SOURCEDIR
- See Also:
-
ENCODING
- See Also:
-
USELEN
- See Also:
-
FILE_NAME
- See Also:
-
PASSES
- See Also:
-
ITERATIONS
- See Also:
-
TIME
- See Also:
-
LINE_MODE
- See Also:
-
BULK_MODE
- See Also:
-
LOCALE
- See Also:
-
TEST_NAME
- See Also:
-
THREADS
- See Also:
-
DURATION
- See Also:
-
ACTION
- See Also:
-
GARBAGE_COLLECT
- See Also:
-
LIST
- See Also:
-
OPTIONS
static final org.apache.commons.cli.Options OPTIONS
-
-
Constructor Details
-
PerfTest
protected PerfTest()Constructor.
-
-
Method Details
-
setup
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
org.apache.commons.cli.Options getOptions() -
run
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:
Exception
-
parseOptions
private Set<String> parseOptions(String[] args) throws PerfTest.UsageException, org.apache.commons.cli.ParseException - Parameters:
args
- command line arguments to parse- Returns:
- the method list to call
- Throws:
PerfTest.UsageException
- parameters parsed, but semantically incorrect or conflictingorg.apache.commons.cli.ParseException
- parameters cannot be parsed
-
getIteration
Translate '-t time' to iterations (or just return '-i iteration')- Throws:
InterruptedException
-
performLoops
- Throws:
InterruptedException
-
gc
protected void gc()Invoke the runtime's garbage collection procedure repeatedly until the amount of free memory stabilizes to within 10%. -
readToEOS
-
readToEOS
-
readLines
-
readDataLine
- Throws:
Exception
-