001package algs34;
002
003import stdlib.*;
004
005public class XPhoneNumberPerformanceTest {
006        private static int NUM_SIZES = 8;
007        private static int START_SIZE = 25000;
008        public static void main(String[] args) {
009                Object val = new Object ();
010                int size = START_SIZE;
011                for (int count=1; count<NUM_SIZES; count++) {
012                        size += size;
013                        //java.util.IdentityHashMap<XPhoneNumber,Object> set = new java.util.IdentityHashMap <>();
014                        java.util.HashMap<XPhoneNumber,Object> set = new java.util.HashMap <>();
015                        //SeparateChainingHashST<XPhoneNumber,Object> set = new SeparateChainingHashST <>();
016                        //LinearProbingHashST<XPhoneNumber,Object> set = new LinearProbingHashST <>();
017                        Stopwatch sw1 = new Stopwatch ();
018                        for (int i=size-1; i>=0; i--) {
019                                XPhoneNumber x = new XPhoneNumber
020                                        (StdRandom.uniform (1000), StdRandom.uniform (1000), StdRandom.uniform (10000));
021                                set.put(x,val);
022                        }
023                        double time1 = sw1.elapsedTime ();
024                        Stopwatch sw2 = new Stopwatch ();
025//                      for (int i=size-1; i>=0; i--) {
026//                              XPhoneNumber x = new XPhoneNumber
027//                                      (StdRandom.uniform (1000), StdRandom.uniform (1000), StdRandom.uniform (10000));
028//                              //set.containsKey (x);
029//                              set.contains (x);
030//                      }
031                        double time2 = sw1.elapsedTime ();
032                        System.out.format ("%9d: add=%f contains=%f\n", size, time1, time2);
033                }
034        }
035}