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 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
  • Field Details

  • Constructor Details

    • PerfTest

      protected PerfTest()
      Constructor.
  • Method Details

    • setup

      protected void setup(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(String[] args) throws 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:
      Exception
    • parseOptions

      private Set parseOptions(String[] args) throws PerfTest.UsageException
      Parameters:
      args -
      Returns:
      the method list to call
      Throws:
      PerfTest.UsageException
    • getIteration

      private long getIteration(String methName, PerfTest.Function fn) throws InterruptedException
      Translate '-t time' to iterations (or just return '-i iteration')
      Parameters:
      meth -
      fn -
      Returns:
      rt
      Throws:
      InterruptedException
    • performLoops

      private long performLoops(PerfTest.Function function, long loops) throws InterruptedException
      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

      public static char[] readToEOS(Reader reader)
    • readToEOS

      public static byte[] readToEOS(InputStream stream)
    • readLines

      protected String[] readLines(String filename, String srcEncoding, boolean bulkMode)
    • readDataLine

      public String readDataLine(BufferedReader br) throws Exception
      Throws:
      Exception