FileDocCategorySizeDatePackage
HashMapPerfTest.javaAPI DocAndroid 1.5 API2874Wed May 06 22:42:02 BST 2009android.core

HashMapPerfTest

public class HashMapPerfTest extends TestCase
Tests basic functionality of HashMaps and prints the time needed to System.out

Fields Summary
private static final Random
sRandom
private static final int
NUM_ELTS
private static final int
ITERS
String[]
keyCopies
private static final boolean
lookupByOriginals
Constructors Summary
Methods Summary
public voidtestHashMapPerformance()


    
         
        StringThing[] st = new StringThing[NUM_ELTS];
        for (int i = 0; i < NUM_ELTS; i++) {
            st[i] = new StringThing();
            keyCopies[i] = st[i].getId();
        }

        // android.os.Debug.startMethodTracing();
        long start = SystemClock.uptimeMillis();
        for (int i = 0; i < ITERS; i++) {
            HashMap<String, StringThing> map = new HashMap<String, StringThing>();
            for (int j = 0; j < NUM_ELTS; j++) {
                StringThing s = st[i];
                map.put(s.getId(), s);
            }
            for (int j = 0; j < NUM_ELTS; j++) {
                if (lookupByOriginals) {
                    StringThing s = st[i];
                    map.get(s.getId());
                } else {
                    map.get(keyCopies[j]);
                }
            }
        }
        long finish = SystemClock.uptimeMillis();
        // android.os.Debug.stopMethodTracing();

        // This should be an assertion instead
        
//        System.out.println("time (" + NUM_ELTS +
//                ", elts, " + ITERS +
//                " iters) = " + (finish - start));