public Form1() { InitializeComponent(); tree = new AleRBTree<AleRBTreeNode<int, string>, int, string>(); }
static void Main(string[] args) { Random rnd = new Random(); PerfData p1 = new PerfData("OrderedSet<KeyValuePair<int, MapNode>>"); PerfData p2 = new PerfData("AleRBTree<int, MapNode>"); for (int j = 0; j < 50; j++) { Dictionary <int, MapNode> u = new Dictionary <int, MapNode>(); int limit = 10000; for (int i = 0; i < limit; ++i) { MapNode n; switch (rnd.Next(2)) { case 1: n = new ClosedNode(); break; default: n = new OpenNode(0.5 + rnd.NextDouble() * 20); break; } int k = rnd.Next(limit * 100); while (u.ContainsKey(k)) { k = rnd.Next(limit * 100); } u[k] = n; } KeyValuePair <int, MapNode>[] src = u.ToArray(); //Console.WriteLine("Calculating times for: Insert + Scan + Delete"); //Console.WriteLine("Calculating times for: Insert"); for (int run = 0; run < 20; run++) { SortedSet <KeyValuePair <int, MapNode> > o1 = new SortedSet <KeyValuePair <int, MapNode> >(new KeyComp <int, MapNode>()); p1.Time(() => { foreach (var nxt in src) { o1.Add(nxt); } foreach (var nxt in src) { if (!o1.Contains(nxt)) { throw new Exception(); } } while (o1.Count > 0) { o1.Remove(o1.First()); } }); } for (int run = 0; run < 20; ++run) { AleRBTree <int, MapNode> o2 = new AleRBTree <int, MapNode>(); p2.Time(() => { foreach (var nxt in src) { o2[nxt.Key] = nxt.Value; } foreach (var nxt in src) { if (!o2.ContainsKey(nxt.Key)) { throw new Exception(); } } while (o2.Count > 0) { o2.DeleteNode(o2.LeftMostKey); } }); } } p1.Dump(); Console.WriteLine(); p2.Dump(); Console.WriteLine(); Console.WriteLine("Relative performance: {0:0.00%} {1}", Math.Abs(p2.Avg / p1.Avg - 1), p1.Avg < p2.Avg ? "slower" : "faster"); /* * PathfinderSample(); * // */ }
public Form1() { InitializeComponent(); tree = new AleRBTree <AleRBTreeNode <int, string>, int, string>(); }