public void Bencmark_FindFirstPreOrder()
        {
            TestNode root  = new TestNode();
            int      depth = 5;

            CreateTestTree(ref root, depth - 1, 3);

            int repetitions = 100000;

            TestNode mark = root.Children[1].Children[2].Children[1].Children[0];

            // Force jitting.
            TestNode node = FindFirstPreOrder <int> .Find(root, n => n.Value == 1000);

            //
            // Search using static method.
            //
            int valueToSearch = 1000;

            mark.Value = valueToSearch;
            DateTime startTime = DateTime.Now;

            for (int r = 0; r < repetitions; ++r)
            {
                node = FindFirstPreOrder <int> .Find(root, n => n.Value == valueToSearch);

                node.Value++;
                valueToSearch++;
            }
            double time = (DateTime.Now - startTime).TotalSeconds;

            Console.WriteLine("Static method: repetitions {0:###,###,###}, time {1} s, {2:###,###,###} searches/s",
                              repetitions, time, repetitions / time);
            //
            // Search using an instance.
            //
            valueToSearch = 1000;
            mark.Value    = valueToSearch;
            FindFirstPreOrder <TestNode, TestNode, int> finder = new FindFirstPreOrder <TestNode, TestNode, int>
            {
                Match = n => n.Value == valueToSearch
            };

            startTime = DateTime.Now;
            for (int r = 0; r < repetitions; ++r)
            {
                finder.Find(root, root);
                finder.Result.Value++;
                valueToSearch++;
            }
            time = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine("Instance     : repetitions {0:###,###,###}, time {1} s, {2:###,###,###} searches/s",
                              repetitions, time, repetitions / time);
        }
예제 #2
0
        static void DumpNode()
        {
            string[]       idElements = _cmdLine.nodeId.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            int            pos        = int.Parse(idElements[0]);
            int            id         = int.Parse(idElements[1]);
            ActionTreeNode node       = FindFirstPreOrder.Find <ActionTree, ActionTreeNode, int>(
                _oppActionTree, _oppActionTree.Positions[pos], n => n.Id == id);

            node.Children.Clear();
            string fileBase = Path.Combine(Path.GetDirectoryName(_cmdLine.oppActionTreeFile),
                                           Path.GetFileNameWithoutExtension(_cmdLine.oppActionTreeFile));
            string fileName = fileBase + "." + _cmdLine.nodeId + ".xml";

            node.XmlSerialize(fileName);
        }
        public void Test_FindFirstPreorder()
        {
            TestNode root = new TestNode();

            CreateTestTree(ref root, 4, 3);

            TestNode node = FindFirstPreOrder <int> .Find(root,
                                                          n => n.Value == 1000);

            Assert.IsNull(node);

            TestNode mark = root.Children[1].Children[2].Children[1];

            mark.Value = 1000;

            // Mark another node further in the tree too.
            root.Children[2].Value = 1000;

            node = FindFirstPreOrder <int> .Find(root, n => n.Value == 1000);

            Assert.AreEqual(mark, node);
        }