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.ArrayAccessRandom
          Task class for benchmarking the access time of an array (integers).
protected static class N08_Part2_DataStructureAccess.ArrayAccessSequential
          Task class for benchmarking the access time of an array (integers).
protected static class N08_Part2_DataStructureAccess.ArrayAccessSynchronizedRandom
          Same code as N08_Part2_DataStructureAccess.ArrayAccessRandom except synchronize on integers around each access.
protected static class N08_Part2_DataStructureAccess.ArrayAccessSynchronizedSequential
          Same code as N08_Part2_DataStructureAccess.ArrayAccessSequential except synchronize on integers around each access.
protected static class N08_Part2_DataStructureAccess.ArrayListAccessRandom
          Same code as N08_Part2_DataStructureAccess.ArrayAccessRandom except use an ArrayList that is equivalent to integers.
protected static class N08_Part2_DataStructureAccess.ArrayListAccessSequential
          Same code as N08_Part2_DataStructureAccess.ArrayAccessSequential except use an ArrayList that is equivalent to integers.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess1Random
          Same code as N08_Part2_DataStructureAccess.HashMapAccessRandom except use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess1Sequential
          Same code as N08_Part2_DataStructureAccess.HashMapAccessSequential except use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess2Random
          Same code as N08_Part2_DataStructureAccess.HashMapAccessRandom except use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.ConcurrentHashMapAccess2Sequential
          Same code as N08_Part2_DataStructureAccess.HashMapAccessSequential except use a ConcurrentHashMap.
protected static class N08_Part2_DataStructureAccess.HashMapAccessRandom
          Same code as N08_Part2_DataStructureAccess.ArrayAccessRandom except use a HashMap that maps integers to integers.
protected static class N08_Part2_DataStructureAccess.HashMapAccessSequential
          Same code as N08_Part2_DataStructureAccess.ArrayAccessSequential except use a HashMap that maps integers to integers.
protected static class N08_Part2_DataStructureAccess.RandomIndex
          Via the next method, returns all the valid indices of integers in seemingly random order.
protected static class N08_Part2_DataStructureAccess.TaskRunnableAbstract
          Abstract base class for all of the other Task classes.
protected static class N08_Part2_DataStructureAccess.ThreadLocalAccessRandom
          Similar code as N08_Part2_DataStructureAccess.HashMapAccessRandom except use a ThreadLocal.
protected static class N08_Part2_DataStructureAccess.ThreadLocalAccessSequential
          Similar code as N08_Part2_DataStructureAccess.HashMapAccessSequential except use a ThreadLocal.
protected static class N08_Part2_DataStructureAccess.TreeMapAccessRandom
          Same code as N08_Part2_DataStructureAccess.HashMapAccessRandom except use a TreeMap.
protected static class N08_Part2_DataStructureAccess.TreeMapAccessSequential
          Same code as N08_Part2_DataStructureAccess.HashMapAccessSequential except use a TreeMap.
protected static class N08_Part2_DataStructureAccess.VectorAccessRandom
          Same code as N08_Part2_DataStructureAccess.ArrayListAccessRandom except use a Vector.
protected static class N08_Part2_DataStructureAccess.VectorAccessSequential
          Same code as N08_Part2_DataStructureAccess.ArrayListAccessSequential except use a Vector.
 
Field Summary
protected static String[] classnamePrefixes
          Specifies the prefixes of the class names of all the task classes that will be benchmarked by main.
protected static Integer[] integers
          Global variable used by the various data structure access task classes like N08_Part2_DataStructureAccess.ArrayAccessSequential.
 
Constructor Summary
N08_Part2_DataStructureAccess()
           
 
Method Summary
protected static Runnable createTask(String prefix, String mode)
           
protected static void examineConcurrentHashMapAnomaly(String mode)
          This method was written to more thoroughly examine the ConcurrentHashMap case 1 versus case 2 anomaly noted in the article as a function of many more element sizes.
static void main(String[] args)
          Results on 2008/3/27 on my 2.2 GHz Intel Core 2 Duo E4500 machine (server jvm): see these files: ..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classnamePrefixes

protected static String[] classnamePrefixes
Specifies the prefixes of the class names of all the task classes that will be benchmarked by main. The classes must all be inner classes of this class. The suffix of their class name must be specified as the 2nd elements of the args parameter of main.


integers

protected static Integer[] integers
Global variable used by the various data structure access task classes like N08_Part2_DataStructureAccess.ArrayAccessSequential.

Is declared as a field here instead of as a field/local variable in the classes below because

  1. it is used by all of the other tasks below
  2. can change it in one single place and have it affect everything else
  3. it will never be garbage collected (unless reassigned)
Values are guaranteed to be unique Integer instances (integers[i].intValue() == i).

Constructor Detail

N08_Part2_DataStructureAccess

public N08_Part2_DataStructureAccess()
Method Detail

main

public static void main(String[] args)
                 throws Exception
Results on 2008/3/27 on my 2.2 GHz Intel Core 2 Duo E4500 machine (server jvm): see these files:

                ../results/N08_Part2_DataStructureAccess_Desktop_1024_Sequential.txt
                ../results/N08_Part2_DataStructureAccess_Desktop_1024_Random.txt
                ../results/N08_Part2_DataStructureAccess_Desktop_1024X1024_Sequential.txt
                ../results/N08_Part2_DataStructureAccess_Desktop_1024X1024_Random.txt
        

Results on 2008/3/27 on my 1.167 GHz SPARC-Enterprise-T5220 machine (server jvm): see these files:


                ../results/N08_Part2_DataStructureAccess_N2_1024_Sequential.txt
                ../results/N08_Part2_DataStructureAccess_N2_1024X1024_Sequential.txt
        
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 mentioned above are the full text of the raw program output. 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 this spreadsheet:


                ../results/N08_Part2_DataStructureAccess.xls
        

Parameters:
args - must be non-null and have exactly 2 elements: args[0] must be an int that specifies the size of the integers array, args[1] must be either the String Sequential or the String Random (it specifies how the elements of the integer array will be accessed)
Throws:
Exception

createTask

protected static Runnable createTask(String prefix,
                                     String mode)
                              throws Exception
Throws:
Exception

examineConcurrentHashMapAnomaly

protected static void examineConcurrentHashMapAnomaly(String mode)
                                               throws Exception
This method was written to more thoroughly examine the ConcurrentHashMap case 1 versus case 2 anomaly noted in the article as a function of many more element sizes.

Results on 2008/5/2 on my 2.2 GHz Intel Core 2 Duo E4500 machine (server jvm):


                m       case 1  case 2
                1       29.798 ns       32.366 ns
                2       28.773 ns       30.201 ns
                4       28.266 ns       25.859 ns
                8       25.361 ns       23.530 ns
                16      27.614 ns       24.478 ns
                32      30.415 ns       26.797 ns
                64      28.893 ns       26.729 ns
                128     29.057 ns       27.718 ns
                256     27.707 ns       27.575 ns
                512     28.846 ns       27.002 ns
                1024    31.326 ns       28.998 ns
                2048    34.486 ns       33.871 ns
                4096    33.757 ns       32.865 ns
                8192    35.414 ns       35.299 ns
                16384   35.290 ns       34.653 ns
                32768   36.722 ns       35.705 ns
                65536   71.930 ns       65.732 ns
                131072  124.900 ns      116.707 ns
                262144  158.120 ns      137.651 ns
                524288  174.524 ns      159.670 ns
                1048576 182.828 ns      164.059 ns
                2097152 194.498 ns      174.439 ns
                4194304 200.627 ns      172.409 ns
                8388608 211.306 ns      184.544 ns
        
The above shows that the anomaly is always present, regardless of the size of the number of elements, which differs from what I found on an earlier run... +++ try another run...

Throws:
Exception