Пример #1
0
        protected RunResult Run(TestDefinition test)
        {
            //localize test settings
            var warmupCount = 0;

            if (test.WarmupCount.HasValue)
            {
                warmupCount = test.WarmupCount.Value;
            }
            var iterationCount = 100;

            if (test.IterationCount.HasValue)
            {
                iterationCount = test.IterationCount.Value;
            }
            var testName = test.TestName ?? test.GetType() + "#" + test.GetHashCode();
            var setup    = test.Setup;
            var run      = test.Run;
            var cleanup  = test.Cleanup;

            //validate
            if (run == null)
            {
                throw new ArgumentNullException(string.Format("Verify that test {0} has a run action.", testName));
            }

            //setup
            try
            {
                if (setup != null)
                {
                    setup();
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            //warmup
            try
            {
                for (var w = 0; w < warmupCount; ++w)
                {
                    run();
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            var runStopwatch       = new Stopwatch();
            var iterationStopwatch = new Stopwatch();
            var iterationCounters  = new List <IterationCounter>();

            //run
            try
            {
                for (var i = 0; i < iterationCount; ++i)
                {
                    iterationStopwatch.Restart();
                    runStopwatch.Start();

                    run();

                    runStopwatch.Stop();
                    iterationStopwatch.Stop();
                    iterationCounters.Add(
                        new IterationCounter
                    {
                        ElapsedMillis = iterationStopwatch.ElapsedMilliseconds,
                        WorkingSet    = GC.GetTotalMemory(false)
                    });
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            var result = new RunResult(testName, runStopwatch.ElapsedMilliseconds, GC.GetTotalMemory(false), iterationCounters);

            //cleanup
            try
            {
                if (cleanup != null)
                {
                    cleanup();
                }
            }
            catch (Exception e)
            {
                result.ReportedException = e;
            }

            //report
            return(result);
        }
Пример #2
0
 public void Register(TestDefinition test)
 {
     _tests.Add(test);
 }
Пример #3
0
        protected RunResult Run(TestDefinition test)
        {
            //localize test settings
            var warmupCount = test.WarmupCount;
            var iterationCount = test.IterationCount;
            var testName = test.TestName ?? test.GetType() + "#" + test.GetHashCode();
            var setup = test.Setup;
            var run = test.Run;
            var cleanup = test.Cleanup;

            //validate
            if (run == null)
            {
                throw new ArgumentNullException(string.Format("Verify that test {0} has a run action.", testName));
            }

            //setup
            try
            {
                if (setup != null)
                {
                    setup();
                }
            }
            catch (Exception e)
            {
                return new RunResult(testName, e);
            }

            //warmup
            try
            {
                for (var w = 0; w < warmupCount; ++w)
                {
                    run(TestHarness.NullHarness);
                }
            }
            catch (Exception e)
            {
                return new RunResult(testName, e);
            }

            var runStopwatch = new Stopwatch();
            var iterationStopwatch = new Stopwatch();
            var iterationCounters = new List<IterationCounter>();

            //run
            try
            {
                for (var i = 0; i < iterationCount; ++i)
                {
                    iterationStopwatch.Reset();

                    var harness = new TestHarness(iterationStopwatch, runStopwatch);
                    run(harness);

                    iterationCounters.Add(
                        new IterationCounter
                            {
                                ElapsedMillis = iterationStopwatch.ElapsedMilliseconds,
                                WorkingSet = GC.GetTotalMemory(false)
                            });
                }
            }
            catch (Exception e)
            {
                return new RunResult(testName, e);
            }

            var result = new RunResult(testName, runStopwatch.ElapsedMilliseconds, GC.GetTotalMemory(false), iterationCounters);

            //cleanup
            try
            {
                if (cleanup != null)
                {
                    cleanup();
                }
            }
            catch (Exception e)
            {
                result.ReportedException = e;
            }

            //report
            return result;
        }
Пример #4
0
 public PerfTestRunner(TestDefinition test)
 {
     _test = test;
 }
Пример #5
0
 public PerfTestRunner(TestDefinition test)
 {
     _test = test;
 }
Пример #6
0
 public void Register(TestDefinition test)
 {
     _tests.Add(test);
 }