Contains information about an algorithm and its performance.
Ejemplo n.º 1
0
        public void Constructor()
        {
            Algorithm algorithm;
            Action action;

            action = () => { };
            algorithm = new Algorithm("asdf", action);
            Assert.AreEqual("asdf", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);

            action = () => { 2.ToString(); };
            algorithm = new Algorithm(action);
            Assert.AreEqual("Algorithm 2", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);

            action = () => { };
            algorithm = new Algorithm("qwer", action);
            Assert.AreEqual("qwer", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);

            algorithm = new Algorithm(null, action);
            Assert.AreEqual("Algorithm 4", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);

            algorithm = new Algorithm("", action);
            Assert.AreEqual("Algorithm 5", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);

            algorithm = new Algorithm(" ", action);
            Assert.AreEqual("Algorithm 6", algorithm.Name);
            Assert.AreEqual(action, algorithm.Action);
        }
Ejemplo n.º 2
0
        public void BenchmarkAndCacheExecutionTime_ReportIndividualIterations()
        {
            Algorithm algorithm = new Algorithm(() => Thread.Sleep(10));

            Stats executionTime = algorithm.BenchmarkAndCacheExecutionTime(100, true);

            Assert.AreEqual(100, executionTime.TotalIterations);
            Assert.IsTrue(1000 < executionTime.Total && executionTime.Total < 2000, "Actual execution time: " + executionTime.Total);
            Assert.IsTrue(executionTime.Min < executionTime.Average);
            Assert.IsTrue(executionTime.Average < executionTime.Max);
        }
Ejemplo n.º 3
0
        public void BenchmarkAndCacheExecutionTime_Formatter()
        {
            Stats executionTime = new Algorithm(() => {}).BenchmarkAndCacheExecutionTime(1, false);

            executionTime.Total = 1000 * 60 * 60 * 24 + 1000 * 60 * 60 + 1000 * 60 + 1000 + 1;
            executionTime.TotalIterations = (int)executionTime.Total;
            executionTime.ExpectedIterations = executionTime.TotalIterations;
            executionTime.Min = 1000 * 60;
            executionTime.Max = 1000 * 60 * 60;

            Assert.AreEqual("Total: 01.01:01:01.001; Min: 01:00.000; Max: 01:00:00.000; Avg: 00.001; Expected: 01.01:01:01.001", executionTime.ToString());
        }
Ejemplo n.º 4
0
 private static void DumpAlgorithmStats(Algorithm algorithm, Algorithm compareTo, bool reportIndividualIterations)
 {
     (algorithm.Name + "\n\tTotal time: " + algorithm.ExecutionTime.Format(algorithm.ExecutionTime.Total) + "\tAverage time: " + algorithm.ExecutionTime.FormatAverage(algorithm.ExecutionTime.Average) +
         (compareTo != null ? "\t\t" + (compareTo.ExecutionTime.Total / algorithm.ExecutionTime.Total).ToString("n2") + " times (" + Math.Abs(100 * (algorithm.ExecutionTime.Total - compareTo.ExecutionTime.Total) / compareTo.ExecutionTime.Total).ToString("n2") + "%) faster than " + compareTo.Name : "")).Dump();
 }