Beispiel #1
0
        public static void Main(string[] args)
        {
            Dictionary<DateTime, int> dic = new Dictionary<DateTime, int> ();
            AVLTree<DateTime, int> tree = new AVLTree<DateTime, int> ();

            for (int i = 0; i < 1000000; i++) {
                dic.Add (DateTime.Now.AddMinutes (i), i);
                tree.add (DateTime.Now.AddMinutes (i), i);
            }

            var min = Convert.ToDateTime ("2013/8/21 4:00:00");
            var max = Convert.ToDateTime ("2013/8/21 5:00:00");

            var watch = Stopwatch.StartNew ();
            var result = dic.Keys.Where (i => i >= min && i <= max).Select (i => dic [i]).ToList ();
            watch.Stop ();
            Console.WriteLine("字典查找耗费时间:{0}ms", watch.ElapsedMilliseconds);

            watch = Stopwatch.StartNew ();
            var result2 = tree.searchRange (min, max);
            watch.Stop ();
            Console.WriteLine("平衡二叉树查找耗费时间:{0}ms", watch.ElapsedMilliseconds);
        }