Ejemplo n.º 1
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Methods
        //---------------------------------------------------------------
        /// <summary>
        /// runs one single test
        /// RunTest is not suited for very short methods, cause the overhead of invoking
        /// a method over the reflection mechanisme is too high
        /// </summary>
        /// <param name="tc">TestCase</param>
        /// <param name="m">Method to test</param>
        protected override void RunTest(TestCaseBase tc, MethodInfo m)
        {
            PerformanceTestCase testCase = (PerformanceTestCase)tc;
            Counter             counter  = Counter.Instance;
            PerformanceTestData td       = new PerformanceTestData();

            td.TestName = m.Name;

            // single invoke
            ulong startCount = counter.Count;

            m.Invoke(testCase, null);
            ulong endCount = counter.Count;

            td.SingleTime = (uint)Counter.GetElapsed(startCount, endCount);

            // multiple invoke
            startCount = counter.Count;
            for (uint i = 0; i < iterations; i++)
            {
                m.Invoke(testCase, null);
            }
            endCount       = counter.Count;
            td.OverallTime = (uint)Counter.GetElapsed(startCount, endCount);
            td.TestNum     = (uint)iterations;

            // raise event and pass testData
            if (testMethod != null)
            {
                testMethod(td);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// runs one single test without using the reflection mechanisme
        /// The overhead is very low and therefore better suited for small methods
        /// However this method doesn't reports results to connected objects like PerformanceTester
        /// </summary>
        /// <param name="testMethod">method (delegate) to test</param>
        /// <returns>test results</returns>
        public PerformanceTestData RunTest(TestCallback testMethod)
        {
            Counter             counter = Counter.Instance;
            PerformanceTestData td      = new PerformanceTestData();

            td.TestName = testMethod.Method.Name;

            // single invoke
            ulong startCount = counter.Count;

            testMethod();
            ulong endCount = counter.Count;

            td.SingleTime = (uint)Counter.GetElapsed(startCount, endCount);

            // multiple invoke
            startCount = counter.Count;
            for (uint i = 0; i < iterations; i++)
            {
                testMethod();
            }
            endCount       = counter.Count;
            td.OverallTime = (uint)Counter.GetElapsed(startCount, endCount);
            td.TestNum     = (uint)iterations;

            return(td);
        }
Ejemplo n.º 3
0
        private void testMethod(PerformanceTestData td)
        {
            currentTestMethod++;
            txtOutput.AppendText("Testing: " + td.TestName + " ... " + Environment.NewLine);
            uint time = (uint)Counter.CalcTime(td.SingleTime);

            txtOutput.AppendText("  Single: " + td.SingleTime + " == " + time + " ms" + Environment.NewLine);
            time = (uint)Counter.CalcTime(td.OverallTime);
            txtOutput.AppendText("  Overall: " + td.OverallTime + " == " + time + "ms" + Environment.NewLine);
            txtOutput.AppendText("-------" + Environment.NewLine);

            TimeSpan ts = DateTime.Now - startTime;

            this.time = (int)ts.TotalMilliseconds;

            UpdateItems();
        }