Package com.oss.util
Class Benchmark
java.lang.Object
com.oss.util.Benchmark
The
Benchmark
is an utility class that can be used for timing
the coder.encode()
and coder.decode()
method
calls. A Benchmark
class instance is initialized with
instances of com.oss.asn1.AbstractData
and
com.oss.asn1.Coder
classes. Invoking the run()
method on the instance will run two coder.encode()
and
coder.decode()
loops in order to determine average
time needed for the specified coder to encode and to decode the data.
After running the test the timing values can be obtained with the
averageEncodeTiming()
and averageDecodeTiming()
method calls.-
Constructor Summary
ConstructorDescriptionBenchmark
(byte[] message, AbstractData type, Coder coder) Construct new performance test which will use specified binary encoding of the value oftype
andCoder
object.Benchmark
(AbstractData value, Coder coder) Construct new performance test which will use specifiedAbstractData
object andCoder
object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns averagedecode()
CPU time per iteration in milliseconds or NaN if CPU time measurement is not available.double
Returns averagedecode()
timing per iteration in milliseconds.double
Returns averagedecode()
time in user mode per iteration in milliseconds or NaN if user time measurement is not available.double
Returns averageencode()
CPU time per iteration in milliseconds or NaN if CPU time measurement is not available.double
Returns averageencode()
timing per iteration in milliseconds.double
Returns averageencode()
time in user mode per iteration in milliseconds or NaN if user time measurement is not available.Returns the exception object indicating an abnormal termination of thedecode()
timing loop.Returns the exception object indicating an abnormal termination of theencode()
timing loop.int
Returns the current setting for the number of samples to collect.numberOfSamples
(int samples) Sets the number of samples to collect.void
run()
Runs encoder and decoder performance tests.int
Returns the current setting for the sampling interval.samplingTime
(int milliseconds) Sets the duration of sampling interval.void
setNumberOfSamples
(int samples) Deprecated.void
setSamplingTime
(int milliseconds) Deprecated.void
setWarmupTime
(int milliseconds) Deprecated.boolean
verbose()
Reports whether progress messages are enabled.verbose
(boolean enable) Enables progress messages while the benchmark is executing.int
Returns the current setting for the warmup timeout of the performance test loop.warmupTime
(int milliseconds) Sets the warmup timeout for the performance test loop.
-
Constructor Details
-
Benchmark
Construct new performance test which will use specifiedAbstractData
object andCoder
object.- Parameters:
value
- test data value. Times required toencode()
anddecode()
the value will be measured.coder
- coder to be used for encoding and decoding the value.
-
Benchmark
Construct new performance test which will use specified binary encoding of the value oftype
andCoder
object.- Parameters:
message
- test binary message. Times required todecode()
andencode()
the value will be measured.type
- empty instance of the AbstractData that identifies the type of the binary message.coder
- coder to be used for encoding and decoding the value.
-
-
Method Details
-
run
public void run()Runs encoder and decoder performance tests. Each test includes running encoder or decoder in a loop for the specified time interval. There are two loops: warmup loop and sampling loop. First the warmup loop is run (by default for 5 seconds) to allow the JVM cache to settle down. Next sampling loop is run (by default for 5 seconds) and number of iterations is counted. The number of iterations is then used to compute average encoding or decoding times. The measured times can be then obtained by calling theaverageEncodeTiming()
andaverageDecodeTiming()
methods. The methods will returnDouble.NaN
value in case of encoder or decoder error. The Exception instance which caused encoder or decoder error can be queried by theencodeExitStatus()
ordecodeExitStatus()
methods. The warmup and sampling intervals are settablesetWarmupTime()
andsetSamplingTime()
methods. By defaultrun()
takes about 20 seconds to execute. -
samplingTime
public int samplingTime()Returns the current setting for the sampling interval.- Returns:
- the current setting for the sampling interval (milliseconds).
-
setSamplingTime
Deprecated.Sets the duration of sampling interval. Shorter durations sacrifice the accuracy. Longer durations result in longer running time. The optimal setting is somewhere between 2000 and 20000 milliseconds. By default, the loop duration of 5000 milliseconds is used. This method has been replaced by thesamplingTime(int)
method.- Parameters:
milliseconds
- the duration of the sampling interval in milliseconds.
-
samplingTime
Sets the duration of sampling interval. Shorter durations sacrifice the accuracy. Longer durations result in longer running time. The optimal setting is somewhere between 2000 and 20000 milliseconds. By default, the loop duration of 5000 milliseconds is used.- Parameters:
milliseconds
- the duration of the sampling interval in milliseconds.- Returns:
- this object.
-
warmupTime
public int warmupTime()Returns the current setting for the warmup timeout of the performance test loop.- Returns:
- the current setting for the warmup timeout of the performance loop (milliseconds).
-
setWarmupTime
Deprecated.Sets the warmup timeout for the performance test loop. At the start of the loop the JVM spends many CPU cycles to compile the bytecodes to native machine instructions. The impact of these aside expenses on the accuracy of timing is dramatic. The warmup timeout instructs the benchmark to run the test loop for the specified number of milliseconds but avoid collecting any performance data at that time. The warmup timeout gives the JVM a chance to complete the compilation of the bytecodes being profiled before the profiler will start to collect the profiling data. Normally, the setting of 5000 - 10000 milliseconds (5-10 seconds) is enough to let the JVM complete with the compilation of the bytecodes. By default, 5000 milliseconds is used. This method has been replaced by thewarmupTime(int)
method.- Parameters:
milliseconds
- the number of milliseconds to "warmup" the timing loop before collecting the data.
-
warmupTime
Sets the warmup timeout for the performance test loop. At the start of the loop the JVM spends many CPU cycles to compile the bytecodes to native machine instructions. The impact of these aside expenses on the accuracy of timing is dramatic. The warmup timeout instructs the benchmark to run the test loop for the specified number of milliseconds but avoid collecting any performance data at that time. The warmup timeout gives the JVM a chance to complete the compilation of the bytecodes being profiled before the profiler will start to collect the profiling data. Normally, the setting of 5000 - 10000 milliseconds (5-10 seconds) is enough to let the JVM complete with the compilation of the bytecodes. By default, 5000 milliseconds is used.- Parameters:
milliseconds
- the number of milliseconds to "warmup" the timing loop before collecting the data.- Returns:
- this object.
-
numberOfSamples
public int numberOfSamples()Returns the current setting for the number of samples to collect.- Returns:
- the current setting for the number of samples to collect.
-
setNumberOfSamples
Deprecated.Sets the number of samples to collect. Bigger values yield better accuracy but require the profiler to run longer. In most cases the optimal setting is in the range 5..10. This method has been replaced by thenumberOfSamples(int)
method.- Parameters:
samples
- the number of samples to collect.
-
numberOfSamples
Sets the number of samples to collect. Bigger values yield better accuracy but require the profiler to run longer. In most cases the optimal setting is in the range 5..10.- Parameters:
samples
- the number of samples to collect.- Returns:
- this object.
-
verbose
public boolean verbose()Reports whether progress messages are enabled.- Returns:
- true if progress messages are enabled.
-
verbose
Enables progress messages while the benchmark is executing.- Parameters:
enable
- enables or disables progress messages.- Returns:
- this object.
-
encodeExitStatus
Returns the exception object indicating an abnormal termination of theencode()
timing loop. If the encode loop has terminated abnormally, say, due to an exception has been thrown, this method returns the exception object, that caused the abnormal termination.- Returns:
- the exit status of the
encode()
operation.
-
decodeExitStatus
Returns the exception object indicating an abnormal termination of thedecode()
timing loop. If the decode loop has terminated abnormally, say, due to an exception has been thrown, this method returns the exception object, that caused the abnormal termination.- Returns:
- the exit status of the
decode()
operation.
-
averageEncodeTiming
public double averageEncodeTiming()Returns averageencode()
timing per iteration in milliseconds.- Returns:
- average timing per encode iteration or
Double.NaN
ifencode()
failed.
-
averageEncodeCPUTiming
public double averageEncodeCPUTiming()Returns averageencode()
CPU time per iteration in milliseconds or NaN if CPU time measurement is not available.- Returns:
- average CPU time per encode iteration or
Double.NaN
ifencode()
failed or CPU time measurement is not available.
-
averageEncodeUserTiming
public double averageEncodeUserTiming()Returns averageencode()
time in user mode per iteration in milliseconds or NaN if user time measurement is not available.- Returns:
- average timing per encode iteration or
Double.NaN
ifencode()
failed or user time measurement is not available.
-
averageDecodeTiming
public double averageDecodeTiming()Returns averagedecode()
timing per iteration in milliseconds.- Returns:
- average timing per encode iteration or
Double.NaN
ifencode()
ordecode()
failed.
-
averageDecodeCPUTiming
public double averageDecodeCPUTiming()Returns averagedecode()
CPU time per iteration in milliseconds or NaN if CPU time measurement is not available.- Returns:
- average timing per encode iteration or
Double.NaN
ifencode()
ordecode()
failed or CPU time measurement is not available.
-
averageDecodeUserTiming
public double averageDecodeUserTiming()Returns averagedecode()
time in user mode per iteration in milliseconds or NaN if user time measurement is not available.- Returns:
- average timing per encode iteration or
Double.NaN
ifencode()
ordecode()
failed or user time measurement is not available.
-