package org.apache.slide.util;

import java.util.Map;
import java.util.HashMap;

/*
 * Created on 01.12.2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */

/**
 * @author olli
 * 
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class DFAMapTest {

    public static void main(String[] args) {
//        Map map = new HashMap(); Map map2 = new HashMap(); Map map3 = new HashMap();
        Map map = new DFAMap(); Map map2 = new DFAMap(); Map map3 = new DFAMap();
//        Map map = new TableDFAMap("key-valu0123456789"); Map map2 = new TableDFAMap("key-valu0123456789"); Map map3 = new TableDFAMap("key-valu0123456789");

        System.gc();

        long put = System.currentTimeMillis();

        System.out.println("PUT START");

        for (int i = 0; i < 100000; i++) {
            String key = "key-" + i;
            String value = "value-" + i;
            map.put(key, value);
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - put));

        long get = System.currentTimeMillis();

        System.out.println("GET START");
        for (int i = 0; i < 100000; i++) {
            String key = "key-" + i;
            String expected = "value-" + i;
            String value = (String) map.get(key);
            if (!expected.equals(value)) {
                System.out.println("**** Expected: " + expected + ", got: " + value);
            }
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - get));

        map = null;
        System.gc();
        
        put = System.currentTimeMillis();

        System.out.println("PUT START #2");

        for (int i = 100000 - 1; i >= 0 ; i--) {
            String key = "key-" + i;
            String value = "value-" + i;
            map2.put(key, value);
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - put));

        get = System.currentTimeMillis();

        System.out.println("GET START #2");
        for (int i = 100000 - 1; i >= 0 ; i--) {
            String key = "key-" + i;
            String expected = "value-" + i;
            String value = (String) map2.get(key);
            if (!expected.equals(value)) {
                System.out.println("**** Expected: " + expected + ", got: " + value);
            }
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - get));

        map2 = null;
        System.gc();
        
        put = System.currentTimeMillis();

        System.out.println("PUT START #3");

        for (int i = 0; i < 100000; i++) {
            String key = i+"-key";
            String value = i+"-value";
            map3.put(key, value);
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - put));

        get = System.currentTimeMillis();

        System.out.println("GET START #3");
        for (int i = 0; i < 100000; i++) {
            String key = i+"-key";
            String expected = i+"-value";
            String value = (String) map3.get(key);
            if (!expected.equals(value)) {
                System.out.println("**** Expected: " + expected + ", got: " + value);
            }
        }
        System.out.println("TOOK: " + (System.currentTimeMillis() - get));

    }
}