pt.tumba.ngram.compression
Class TestStatistics

java.lang.Object
  extended by pt.tumba.ngram.compression.TestStatistics
All Implemented Interfaces:
java.lang.Comparable

 class TestStatistics
extends java.lang.Object
implements java.lang.Comparable

Package local helper class to compute statistics for a single compression experiment. Stores original and coded bytes, average and cumulative compression and speeds. Pretty printing is through toString.

Author:
Bruno Martins
See Also:
TestSet

Field Summary
private  java.lang.String _name
          Name of test.
private  int _numTests
          Number of tests that have been run.
private  int _totalCodedBytes
          Cumulative number of coded bytes.
private  double _totalCompressionRate
          Running total of sum of compression rates per file (for average).
private  double _totalDecodeSpeed
          Total of KB/s rate for all decodings (for average).
private  long _totalDecodeTime
          Total amount of time in milliseconds spent decoding.
private  double _totalEncodeSpeed
          Total of KB/s rate for all encodings (for average).
private  long _totalEncodeTime
          Total amount of time in milliseconds spent encoding.
private  int _totalOriginalBytes
          Cumulative number of original bytes.
 
Constructor Summary
TestStatistics(java.lang.String name)
           
 
Method Summary
 int compareTo(java.lang.Object that)
          Compare using average compression rates, breaking ties by name.
private  int compareTo(TestStatistics that)
          Compare using average compression rates, breaking ties by name.
(package private)  java.lang.String lineReport()
          Used for a line of reporting by TestSet.
private static double rate(long a, long b)
          Rate of first argument divided by second argument as doubles.
(package private)  void record(int originalBytes, int codedBytes, long encodeTime, long decodeTime)
          Record the result of an experiment with specified number of original and encoded bytes with specified encode and decode time.
private static java.lang.String roundOff(double x)
          Round off a double to 2 decimal places, taking up 8 total characters.
private static java.lang.String roundOff(double x, double factor, int width)
          Round off a double with a multiplicative factor, padding to specified width.
private static java.lang.String roundOff(double x, int width, int numDecimalPlaces)
          Round off a double to specified number of decimal places, taking up specified total width
 java.lang.String toString()
          Returns a String version of the Test report.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_name

private java.lang.String _name
Name of test.


_totalOriginalBytes

private int _totalOriginalBytes
Cumulative number of original bytes.


_totalCodedBytes

private int _totalCodedBytes
Cumulative number of coded bytes.


_numTests

private int _numTests
Number of tests that have been run.


_totalEncodeSpeed

private double _totalEncodeSpeed
Total of KB/s rate for all encodings (for average).


_totalDecodeSpeed

private double _totalDecodeSpeed
Total of KB/s rate for all decodings (for average).


_totalCompressionRate

private double _totalCompressionRate
Running total of sum of compression rates per file (for average).


_totalEncodeTime

private long _totalEncodeTime
Total amount of time in milliseconds spent encoding.


_totalDecodeTime

private long _totalDecodeTime
Total amount of time in milliseconds spent decoding.

Constructor Detail

TestStatistics

TestStatistics(java.lang.String name)
Method Detail

compareTo

public int compareTo(java.lang.Object that)
Compare using average compression rates, breaking ties by name. Assumes tests have been run on same set.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Returns a String version of the Test report.

Overrides:
toString in class java.lang.Object

record

void record(int originalBytes,
            int codedBytes,
            long encodeTime,
            long decodeTime)
Record the result of an experiment with specified number of original and encoded bytes with specified encode and decode time.

Parameters:
originalBytes - Number of bytes in original source.
codedBytes - Number of bytes in decoded result.
encodeTime - Time taken to do encoding in milliseconds.
decodeTime - Time taken to do decoding in milliseconds.

lineReport

java.lang.String lineReport()
Used for a line of reporting by TestSet.

Returns:
The string representation of the statistics for this test on one line.

compareTo

private int compareTo(TestStatistics that)
Compare using average compression rates, breaking ties by name. Assumes tests have been run on same set.

Specified by:
compareTo in interface java.lang.Comparable

rate

private static double rate(long a,
                           long b)
Rate of first argument divided by second argument as doubles.

Parameters:
a - Numerator.
b - Denominator.
Returns:
Numerator over denominator with double division.

roundOff

private static java.lang.String roundOff(double x)
Round off a double to 2 decimal places, taking up 8 total characters.

Parameters:
x - Double to round off and convert to string.
Returns:
Result of rounding as string.

roundOff

private static java.lang.String roundOff(double x,
                                         int width,
                                         int numDecimalPlaces)
Round off a double to specified number of decimal places, taking up specified total width

Parameters:
x - Double to round off and convert to string.
width - Width of final string representation.
numDecimalPlaces - Number of decimal places in representation.
Returns:
Result of rounding as string.

roundOff

private static java.lang.String roundOff(double x,
                                         double factor,
                                         int width)
Round off a double with a multiplicative factor, padding to specified width.

Parameters:
x - Double to round off and convert to string.
width - Width of final string representation.
factor - 10 to the number of decimal places to keep.
Returns:
Result of rounding as string.