diff --git a/icu4j/src/com/ibm/icu/dev/test/PerfTest.java b/icu4j/src/com/ibm/icu/dev/test/PerfTest.java new file mode 100644 index 00000000000..a9a602df75f --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/test/PerfTest.java @@ -0,0 +1,73 @@ +/* +********************************************************************** +* Copyright (c) 2002, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/Attic/PerfTest.java,v $ +* $Date: 2002/09/19 23:00:52 $ +* $Revision: 1.1 $ +********************************************************************** +*/ + +package com.ibm.icu.dev.test; +import com.ibm.icu.text.NumberFormat; + +/** + * A class for doing performance testing. To use, subclass and + * implement the test() method. + */ +public abstract class PerfTest { + + /** + * Subclasses must implement this method to do the action to + * be measured. + * @return the number of iterations run by this method, >= 1. + */ + protected abstract int test(); + + /** + * Measure the time required by the test() method. + * @param iterations number of times to call test(). Must be >= 1. + * @return the time per iteration in seconds. Iterations, in this + * case, are counted as 'iterations' * the result of test() or + * empty(). + */ + public double measure(int iterations, TestLog log) { + if (iterations < 0) { + throw new IllegalArgumentException("Invalid iterations"); + } + + int i, count; + + double start, stop, limit; + + // Call test() first + count = 0; + start = System.currentTimeMillis(); + for (i=0; i s + } + + /** + * Convenience. + */ + public final double measure(int iterations) { + return measure(iterations, null); + } + + static NumberFormat nf = NumberFormat.getInstance(); +} + +//eof