Class N08_Part2_DataStructureAccess

java.lang.Object
  extended by N08_Part2_DataStructureAccess

public class N08_Part2_DataStructureAccess
extends Object

For the article Robust Java benchmarking, Part 2: Statistics And solutions, contains the code relevant to Figure 3, Figure 4, Figure 5, Listing 2, and Listing 3.

Author:
Brent Boyer

Nested Class Summary
protected static class N08_Part2_DataStructureAccess.ArrayAccess
          Task class for benchmarking the access time of an array (N08_Part2_DataStructureAccess.ArrayAccess.integers).
protected static class N08_Part2_DataStructureAccess.ArrayAccessSynchronized
          Same code as N08_Part2_DataStructureAccess.ArrayAccess except synchronize on N08_Part2_DataStructureAccess.ArrayAccess.integers around each access.
protected static class N08_Part2_DataStructureAccess.ArrayListAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.ListAccess to use an ArrayList.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess1
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess16
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.ConcurrentSkipListMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a ConcurrentSkipListMap.
protected static class N08_Part2_DataStructureAccess.CopyOnWriteArrayListAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.ListAccess to use a CopyOnWriteArrayList.
protected static class N08_Part2_DataStructureAccess.HashMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a HashMap.
protected static class N08_Part2_DataStructureAccess.HashtableAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a Hashtable.
protected static class N08_Part2_DataStructureAccess.IdentityHashMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use an IdentityHashMap.
protected static class N08_Part2_DataStructureAccess.LinkedHashMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a LinkedHashMap.
protected static class N08_Part2_DataStructureAccess.ListAccess
          Same code as N08_Part2_DataStructureAccess.ArrayAccess except use a List that is equivalent to the result of makeIntegers.
protected static class N08_Part2_DataStructureAccess.MapAccess
          Same code as N08_Part2_DataStructureAccess.ArrayAccess except use a Map that is equivalent to the result of makeIntegers.
protected static class N08_Part2_DataStructureAccess.Mode
          Enum of all the supported data structure access pattern modes.
protected static class N08_Part2_DataStructureAccess.TaskAbstract
          Abstract base class for Tasks which measure the access time of "array-like" data structures: arrays, array-like Lists (e.g.
protected static class N08_Part2_DataStructureAccess.ThreadLocalAccess
          Similar code to N08_Part2_DataStructureAccess.MapAccess except use a ThreadLocal.
protected static class N08_Part2_DataStructureAccess.TreeMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a TreeMap.
protected static class N08_Part2_DataStructureAccess.VectorAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.ListAccess to use a Vector.
protected static class N08_Part2_DataStructureAccess.WeakHashMapAccess
          Simply causes its superclass N08_Part2_DataStructureAccess.MapAccess to use a WeakHashMap.
 
Field Summary
protected static String class_key
           
protected static List<String> keysLegal
          Specifies all the switch keys which can legally appear as command line arguments to main.
protected static String mode_key
           
protected static String pathPrefix_key
           
protected static String size_key
           
 
Constructor Summary
N08_Part2_DataStructureAccess()
           
 
Method Summary
protected static N08_Part2_DataStructureAccess.TaskAbstract getTask(String className, int size, N08_Part2_DataStructureAccess.Mode mode)
           
static void main(String[] args)
          Entry point to the functionality offered by this class.
protected static int[] makeGeometricSeries(int start, int end, int n)
          Generates the double-valued geometric series [start, start * r, start * r^2, ..., start * r^(n-1)].
protected static void outputFull(String className, N08_Part2_DataStructureAccess.Mode mode, int size, String pathPrefix, bb.util.Benchmark benchmark, String result)
          Writes the full results to a file.
protected static void outputMeanOnly(String className, N08_Part2_DataStructureAccess.Mode mode, int size, String pathPrefix, bb.util.Benchmark benchmark, String result)
          Writes the mean-only results to a file that is suitable for loading into a spreadsheet for graphing.
protected static void resultsToFile(String className, int size, N08_Part2_DataStructureAccess.Mode mode, String pathPrefix, bb.util.Benchmark benchmark, String result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

class_key

protected static final String class_key
See Also:
Constant Field Values

mode_key

protected static final String mode_key
See Also:
Constant Field Values

size_key

protected static final String size_key
See Also:
Constant Field Values

pathPrefix_key

protected static final String pathPrefix_key
See Also:
Constant Field Values

keysLegal

protected static final List<String> keysLegal
Specifies all the switch keys which can legally appear as command line arguments to main.

Constructor Detail

N08_Part2_DataStructureAccess

public N08_Part2_DataStructureAccess()
Method Detail

main

public static void main(String[] args)
                 throws Exception
Entry point to the functionality offered by this class.

Results on 2008-03-27 on my 2.2 GHz Intel Core 2 Duo E4500 machine (server jvm) are in the ../results/N08_Part2_DataStructureAccess_Desktop_XXX.txt series of files.

Results on 2008-03-27 on my 1.167 GHz SPARC-Enterprise-T5220 machine (server jvm) are in the ../results/N08_Part2_DataStructureAccess_N2_XXX.txt series of files. Note: the N2 results are CPU times, not elapsed times (since the tests are all single threaded and Solaris supports this so well)

The files above contain the full Benchmark reports. Edited versions of the relevant data (i.e. just the means) of all of the above results, plus all of the associated Figures in the article, are found in the spreadsheet ../results/N08_Part2_DataStructureAccess.xls.

Results on 2009-12-20 on my 2.5 GHz Intel Xeon E5420 machine (server jvm) are in the .../results/newPostArticleResults/dataStructureAccess directory.

Parameters:
args - must be non-null and have exactly 8 elements; these 8 elements must consist of these 4 command line switches (name/value pairs); the switches may be in any order: -class [the name of one of the task inner classes e.g. ArrayAccess], -mode [either sequential or random], -size [the number of elements in the data structure, as an int], -pathPrefix [valid file system path prefix; the final part of the file name will be generated by this class]
Throws:
Exception - (or some subclass) if any problem happens

getTask

protected static N08_Part2_DataStructureAccess.TaskAbstract getTask(String className,
                                                                    int size,
                                                                    N08_Part2_DataStructureAccess.Mode mode)
                                                             throws Exception
Throws:
Exception

resultsToFile

protected static void resultsToFile(String className,
                                    int size,
                                    N08_Part2_DataStructureAccess.Mode mode,
                                    String pathPrefix,
                                    bb.util.Benchmark benchmark,
                                    String result)
                             throws Exception
Throws:
Exception

outputMeanOnly

protected static void outputMeanOnly(String className,
                                     N08_Part2_DataStructureAccess.Mode mode,
                                     int size,
                                     String pathPrefix,
                                     bb.util.Benchmark benchmark,
                                     String result)
                              throws Exception
Writes the mean-only results to a file that is suitable for loading into a spreadsheet for graphing.

Throws:
Exception

outputFull

protected static void outputFull(String className,
                                 N08_Part2_DataStructureAccess.Mode mode,
                                 int size,
                                 String pathPrefix,
                                 bb.util.Benchmark benchmark,
                                 String result)
                          throws Exception
Writes the full results to a file.

Throws:
Exception

makeGeometricSeries

protected static int[] makeGeometricSeries(int start,
                                           int end,
                                           int n)
                                    throws IllegalArgumentException
Generates the double-valued geometric series [start, start * r, start * r^2, ..., start * r^(n-1)]. In other words, generates n values, the first of which is start, and the last of which is end, which have the property that the ratio of sucessive elements is a constant r. This last property causes a logarithmic plot of the values to have uniform point density.

The result that is actually returned is an int rounded version of that double-valued sequence that is guaranteed to have no duplicate elements. Thus, the size of the result may be less than n (but will never exceed it) and the ratio of successive elements may not exactly equal a constant r (because of the rounding).

Parameters:
start - the first element in the result, guaranteed
end - the last element in the result, guaranteed
n - number of elements that would like the result to contain; the actual size of the result may be less than this
Throws:
IllegalArgumentException