com.sosnoski.xmlbench
Class BenchDocBase

java.lang.Object
  |
  +--com.sosnoski.xmlbench.BenchBase
        |
        +--com.sosnoski.xmlbench.BenchDocBase
Direct Known Subclasses:
BenchDOM, BenchDOM4J, BenchElectric, BenchJDOM, BenchXPP

public abstract class BenchDocBase
extends BenchBase

Abstract base class for document representation benchmark tests. This class defines the basic tests along with some implementation methods which must be defined by the subclass for each particular document representation to be tested.

Version:
1.2
Author:
Dennis M. Sosnoski

Fields inherited from class com.sosnoski.xmlbench.BenchBase
ATTRCHAR_COUNT_INDEX, ATTRIBUTE_COUNT_INDEX, AVERAGE_SPACE_INDEX, BUILD_AVERAGE_INDEX, BUILD_MIN_INDEX, CONTENT_COUNT_INDEX, DELTA_MEMORY_INDEX, ELEMENT_COUNT_INDEX, FIRST_SPACE_INDEX, GARBAGE_COLLECT_DELAY, GARBAGE_UNIT_DELAY, INITIAL_MEMORY_INDEX, m_configName, m_configVariant, m_lastMemory, m_lastTime, m_printPass, m_printStream, m_printSummary, MODIFY_AVERAGE_INDEX, MODIFY_MIN_INDEX, s_spaceFullDescriptions, s_spaceShortDescriptions, s_timeFullDescriptions, s_timeShortDescriptions, SERIALIZE_AVERAGE_INDEX, SERIALIZE_MIN_INDEX, SERIALIZE_SIZE_INDEX, SPACE_RESULT_COUNT, TEXT_AVERAGE_INDEX, TEXT_MIN_INDEX, TEXTCHAR_COUNT_INDEX, TIME_RESULT_COUNT, UNSERIALIZE_AVERAGE_INDEX, UNSERIALIZE_MIN_INDEX, WALK_AVERAGE_INDEX, WALK_MIN_INDEX, WALKED_SPACE_INDEX
 
Constructor Summary
protected BenchDocBase(java.lang.String config)
          Constructor.
 
Method Summary
protected abstract  java.lang.Object build(java.io.InputStream in)
          Build document representation by parsing XML.
protected abstract  void modify(java.lang.Object document)
          Modify a document representation.
protected abstract  void output(java.lang.Object document, java.io.OutputStream out)
          Output a document as XML text.
protected  void reset()
          Reset test class instance.
 int[] runSpaceTest(int passes, int excludes, byte[][] texts)
          Main space test method.
 int[] runTimeTest(int passes, int excludes, byte[][] texts)
          Main time test method.
protected  boolean serialize(java.lang.Object doc, java.io.OutputStream out)
          Serialize a document to a byte array.
protected  java.lang.Object unserialize(java.io.InputStream in)
          Unserialize a document from a byte array.
protected abstract  void walk(java.lang.Object doc, DocumentSummary summary)
          Walk and summarize document.
 
Methods inherited from class com.sosnoski.xmlbench.BenchBase
getName, initMemory, initTime, printSummary, reportSpace, reportTime, reportValue, setPrint, setShowDocument, setShowPass, setVariant, testPassSpace, testPassTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BenchDocBase

protected BenchDocBase(java.lang.String config)
Constructor.
Parameters:
config - test configuration name
Method Detail

build

protected abstract java.lang.Object build(java.io.InputStream in)
Build document representation by parsing XML. This method must be implemented by each subclass to use the appropriate construction technique.
Parameters:
in - XML document input stream
Returns:
document representation

walk

protected abstract void walk(java.lang.Object doc,
                             DocumentSummary summary)
Walk and summarize document. This method should walk through the nodes of the document, accumulating summary information. It must be implemented by each subclass.
Parameters:
doc - document representation to be walked
summary - output document summary information

output

protected abstract void output(java.lang.Object document,
                               java.io.OutputStream out)
Output a document as XML text. This method must be implemented by each subclass to use the appropriate output technique.
Parameters:
doc - document representation to be output
out - XML document output stream

modify

protected abstract void modify(java.lang.Object document)
Modify a document representation. This method must be implemented by each subclass to walk the document representation performing the following modifications: remove all content segments which consist only of whitespace; add an attribute "text" set to "true" to any elements which directly contain non-whitespace text content; and replace each non-whitespace text content segment with a "text" element which wraps the content.
Parameters:
doc - document representation to be modified

reset

protected void reset()
Reset test class instance. This method should be overridden by any subclasses which retain state information during the execution of a test. Any such information should be cleared when this method is called.

serialize

protected boolean serialize(java.lang.Object doc,
                            java.io.OutputStream out)
Serialize a document to a byte array.
Parameters:
doc - document representation to be serialized
out - serialized document output stream
Returns:
true if successful, false if representation does not support serialization

unserialize

protected java.lang.Object unserialize(java.io.InputStream in)
Unserialize a document from a byte array.
Parameters:
in - serialized document input stream
Returns:
unserialized document representation

runTimeTest

public int[] runTimeTest(int passes,
                         int excludes,
                         byte[][] texts)
Main time test method. This implementation of the abstract base class method performs the normal sequence of speed tests. Subclasses which cannot use the normal test sequence must override this method with their own variation.
Overrides:
runTimeTest in class BenchBase
Parameters:
passes - number of passes of each test
excludes - number of initialization passes excluded from averages
texts - document texts for test
Returns:
result times array

runSpaceTest

public int[] runSpaceTest(int passes,
                          int excludes,
                          byte[][] texts)
Main space test method. This implementation of the abstract base class method performs the normal sequence of space tests.
Overrides:
runSpaceTest in class BenchBase
Parameters:
passes - number of passes of each test
excludes - number of initialization passes excluded from averages
texts - document texts for test
Returns:
result values array


Company Web Site

XML Benchmark Home