public void LargeTreeTest()
        {
            TreeNode root = new TreeNode("Root");
            var      flat = new ObservableFlatTreeStore();

            flat.RootNode = root;

            const int kFirstBatchCount  = 200;
            const int kSecondBatchCount = 2000;
            const int kThirdBatchCount  = 200;

            // 100% increase from batch 1 → 2 - this due to reallocations of OC - it's meant as an acceptable maximum
            const double kAcceptablePercentIncrease_1_to_2 = 1.0;

            // 75% increase from batch 2 → 3
            const double kAcceptablePercentIncrease_2_to_3 = 0.75;

            // 100% increase from batch 1 → 3
            const double kAcceptablePercentIncrease_1_to_3 = 1.00;

            Kernal32_Timer timer     = new Kernal32_Timer();
            int            itemCount = kFirstBatchCount;

            timer.Start();
            var    leaves  = this.ConstructTree(root, itemCount);
            double seconds = timer.Stop();

            double averageSeconds1 = seconds / kFirstBatchCount;

            Console.WriteLine($"Run 1 => Took {seconds} seconds to add {kFirstBatchCount}");
            Console.WriteLine($"Run 1 => Average of {averageSeconds1} seconds per item");
            Console.WriteLine("-----------------------------------------");

            timer.Start();
            ConstructTree(leaves, itemCount, itemCount += kSecondBatchCount);
            seconds = timer.Stop();
            double averageSeconds2 = seconds / kSecondBatchCount;
            double increase_1_to_2 = (averageSeconds2 - averageSeconds1) / averageSeconds2;

            Console.WriteLine($"Run 2 => Adding an additional {kSecondBatchCount} took {seconds}");
            Console.WriteLine($"Run 2 => Average of {averageSeconds2} seconds per item");
            Console.WriteLine($"Run 2 => Change in percent, {increase_1_to_2 * 100.0:N2}%");
            Console.WriteLine("-----------------------------------------");
            Assert.IsTrue(increase_1_to_2 < kAcceptablePercentIncrease_1_to_2, $"Average seconds per add increased from frist {kFirstBatchCount} by over {kAcceptablePercentIncrease_1_to_2 * 100.0}%");

            timer.Start();
            ConstructTree(leaves, itemCount, itemCount += kThirdBatchCount);
            seconds = timer.Stop();
            double averageSeconds3 = seconds / kThirdBatchCount;
            double increase_1_to_3 = (averageSeconds3 - averageSeconds1) / averageSeconds3;
            double increase_2_to_3 = (averageSeconds3 - averageSeconds2) / averageSeconds3;

            Console.WriteLine($"Run 3 => Adding an additional {kThirdBatchCount} took {seconds}");
            Console.WriteLine($"Run 3 => Average of {averageSeconds3} seconds per item");
            Console.WriteLine($"Run 3 => % change in average from the first batch of {kFirstBatchCount}   -> {increase_1_to_3 * 100.0:N2}%");
            Console.WriteLine($"Run 3 => % change in average from the second batch of {kSecondBatchCount} -> {increase_2_to_3 * 100.0:N2}%");
            Console.WriteLine("-----------------------------------------");

            Assert.IsTrue(increase_2_to_3 < kAcceptablePercentIncrease_2_to_3, $"Average seconds per add increased from second {kSecondBatchCount} by over {kAcceptablePercentIncrease_1_to_3 * 100.0}%");
            Assert.IsTrue(increase_1_to_3 < kAcceptablePercentIncrease_1_to_3, $"Average seconds per add increased from second {kSecondBatchCount} by over {kAcceptablePercentIncrease_1_to_3 * 100.0}%");
        }
Beispiel #2
0
        public void Stratabase_ReferenceLists_TreeTest()
        {
            Kernal32_Timer timer = new Kernal32_Timer();

            /*      Root
             *      /|\
             *     / | \
             *    A  B  C
             *       |
             *       D
             * */
            timer.Start();
            TreeItem R = new TreeItem {
                Name = "Root"
            };
            TreeItem A = new TreeItem {
                Name = "A"
            };
            TreeItem B = new TreeItem {
                Name = "B"
            };
            TreeItem C = new TreeItem {
                Name = "C"
            };
            TreeItem D = new TreeItem {
                Name = "D"
            };

            R.Children.Add(A);
            R.Children.Add(C);

            B.Children.Add(D);
            double setup = timer.Stop();

            timer.Stop();
            Stratabase sb = new Stratabase(1);

            sb.SetBaselineFromPropertiesOf(R);
            double sballocs = timer.Stop();

            timer.Start();
            StrataTreeItem r       = new StrataTreeItem(sb, R.Id);
            StrataTreeItem a       = r.Children[0];
            StrataTreeItem b       = r.InsertItemIntoBaseline(1, B);
            StrataTreeItem c       = r.Children[2];
            StrataTreeItem d       = b.Children[0];
            double         reftree = timer.Stop();


            Assert.AreEqual(R.Name, r.Name);
            Assert.AreEqual(A.Name, a.Name);
            Assert.AreEqual(B.Name, b.Name);
            Assert.AreEqual(C.Name, c.Name);
            Assert.AreEqual(D.Name, d.Name);

#if false // Speed test & output
            timer.Start();
            const int kAutomated = 100;
            for (int i = 0; i < kAutomated; ++i)
            {
                c.InsertIntoBaseline(i, new TreeItem {
                    Name = $"Automated #{i}"
                });
            }
            double followupGeneration = timer.Stop();

            Console.WriteLine($"Setup took {setup * 1000} miliseconds");
            Console.WriteLine($"Stratabase allocs took {sballocs * 1000} miliseconds");
            Console.WriteLine($"Ref tree allocs took {reftree * 1000} miliseconds");
            Console.WriteLine($"Followup ref generation of {kAutomated} took {followupGeneration * 1000} miliseconds");
#endif
        }