Esempio n. 1
0
        public void RunTest()
        {
            var performanceTest = performanceTests.FirstOrDefault(test => test.Name == testToExecute);

            if (performanceTest == null)
            {
                throw new KeyNotFoundException($"Test {testToExecute} could not be found!");
            }

            test = (IPerformanceTest)Activator.CreateInstance(performanceTest) !;

            var oldLatencyMode    = GCSettings.LatencyMode;
            var oldThreadPriority = Thread.CurrentThread.Priority;

            GC.Collect();
            GCSettings.LatencyMode        = GCLatencyMode.SustainedLowLatency;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            globalStats = new ConcurrentQueue <Statistic>();
            rps         = new List <int>(Math.Min(5000, runTimeInSeconds));
            GC.Collect();

            LaunchTest();

            Thread.CurrentThread.Priority = oldThreadPriority;
            GCSettings.LatencyMode        = oldLatencyMode;
        }
        /// <summary>
        /// Internal method that runs a single test.
        /// </summary>
        /// <param name="test">The test to run.</param>
        /// <param name="iterations">Number of times to run the test.</param>
        /// <param name="data">Data to pass to the test.</param>
        private void InternalRun(IPerformanceTest test, int iterations, object?data)
        {
            Stopwatch stopwatch = new();

            // Allow test class to initialize iteself
            test.Initialize(data);

            // Keep iterations positive
            iterations = Math.Max(iterations, 1);

            // Run this test
            for (int i = 0; i < iterations; i++)
            {
                stopwatch.Start();
                test.Run(data);
                stopwatch.Stop();
            }

            // Add the result
            TestResults.Add(new TestResult
            {
                Description  = test.Description,
                Milliseconds = stopwatch.ElapsedMilliseconds,
            });
        }
Esempio n. 3
0
        private static void RunTest(Type t, Action <TimeSpan> action)
        {
            int pagesize = 50;
            IPerformanceTest instance = Activator.CreateInstance(t, pagesize) as IPerformanceTest;

            long sumTicks = 0;
            int  count1   = 10;                         // 大循环次数
            int  count2   = 3000;                       // 每轮循环中调用方法次数

            for (int i = 0; i < count1; i++)
            {
                Stopwatch watch = Stopwatch.StartNew();

                for (int k = 0; k < count2; k++)
                {
                    var result = instance.Run();
                    instance.Dispose();
                }

                watch.Stop();

                sumTicks += watch.Elapsed.Ticks;
                action(watch.Elapsed);
            }

            TimeSpan ts = new TimeSpan(sumTicks / count1);

            action(ts);
        }
        private static void RunTests(IPerformanceTest performanceTest, string testName)
        {
            try
            {
                Logger.WriteToScreen(testName, ConsoleColor.Cyan);
                Logger.WriteToScreen("---------------------------", ConsoleColor.Cyan);
                Logger.WriteToScreen(String.Format("Starting performance test"), ConsoleColor.Green);

                StopwatchObj.Start();

                performanceTest.RunRegistrationTests();

                Logger.WriteToScreen(String.Format("IOC Registration Time for {0} tests: {1} ms", NumberOfTests, StopwatchObj.Elapsed.Milliseconds.ToString()));

                StopwatchObj.Restart();

                performanceTest.RunResolveTests();

                Logger.WriteToScreen(String.Format("IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, StopwatchObj.Elapsed.Milliseconds.ToString()));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
            finally
            {
                StopwatchObj.Stop();

                Logger.WriteToScreen("Ending performance test\n", ConsoleColor.Red);
            }
        }
Esempio n. 5
0
 private void WriteTestLog(StreamWriter log, IPerformanceTest test)
 {
     foreach (var line in test.GetLogLines())
     {
         log.WriteLine(line);
     }
 }
Esempio n. 6
0
        static void BeginTest(IPerformanceTest test)
        {
            //插入
            //Console.WriteLine();
            //_watch.Restart();
            //int num = test.InsertData(insertNum);
            //_watch.Stop();
            //if (num > 0)
            //{
            //    Console.WriteLine(string.Format("{0}插入{1}条数据用时:{2}毫秒,平均每条耗时{3}毫秒", test.TestName, insertNum, _watch.ElapsedMilliseconds, _watch.ElapsedMilliseconds / insertNum));
            //}

            //return;

            //查询
            _watch.Restart();
            int mapNum = 0;

            for (int i = 0; i < selectNum; i++)
            {
                //test.InsertData(1);
                mapNum = test.GetData(1);
            }
            _watch.Stop();
            Console.WriteLine(string.Format("{0}查询测试:映射{1}条数据,执行{2}次总耗时{3}毫秒,平均耗时{4}毫秒", test.TestName, mapNum, selectNum, _watch.ElapsedMilliseconds, _watch.ElapsedMilliseconds / selectNum));
        }
 public static long Run(IPerformanceTest test) {
     test.Before();
     _stopwatch.Reset();
     _stopwatch.Start();
     test.Run();
     _stopwatch.Stop();
     return _stopwatch.ElapsedMilliseconds;
 }
 public static long Run(IPerformanceTest test)
 {
     test.Before();
     _stopwatch.Reset();
     _stopwatch.Start();
     test.Run();
     _stopwatch.Stop();
     return(_stopwatch.ElapsedMilliseconds);
 }
Esempio n. 9
0
 public static long Run(IPerformanceTest test)
 {
     test.Before();
     STOPWATCH.Reset();
     STOPWATCH.Start();
     test.Run();
     STOPWATCH.Stop();
     return(STOPWATCH.ElapsedMilliseconds);
 }
    protected override IPerformanceTest InitView()
    {
        var networkSpawnTests = new IPerformanceTest[count];

        for (int i = 0; i < networkSpawnTests.Length; ++i)
        {
            networkSpawnTests[i] = new NetworkSpawnPerformanceTest(networkPrefab);
        }
        return(new PerformanceTestScheduler(networkSpawnTests));
    }
        /// <summary>
        /// Runs the specified test.
        /// </summary>
        /// <param name="test">The test to run.</param>
        /// <param name="iterations">Number of times to run the test.</param>
        /// <param name="data">Optional data to pass to the test.</param>
        /// <returns>The test results.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="test"/>
        /// is <c>null</c>.</exception>
        public IEnumerable <TestResult> Run(IPerformanceTest test, int iterations = 1, object?data = null)
        {
            if (test == null)
            {
                throw new ArgumentNullException(nameof(test));
            }

            PrepareTests();
            InternalRun(test, iterations, data);
            ConcludeTests(iterations);
            return(TestResults);
        }
Esempio n. 12
0
        // On my system the result compared to classic implementation is:
        // Commit 0dca2387: 10 times slower, on average 3.6 µs per cal
        // Commit dcdf4581: 10 times slower, on average 4.0 µs per cal
        public void PerformanceTestCallMethod()
        {
            IPerformanceTest classic = new Classic {
                Name = "Name"
            };
            IPerformanceTest newWay     = factory.Create();
            const int        callCount1 = 1000000;
            const int        callCount2 = 100000;

            PerformanceTest(
                () => classic.Format("Something {0}"), callCount1,
                () => newWay.Format("Something {0}"), callCount2);
        }
Esempio n. 13
0
        static void BeginTest(IPerformanceTest test)
        {
            //插入
            //Console.WriteLine();
            //_watch.Restart();
            //int num = test.InsertData(insertNum);
            //_watch.Stop();
            //if (num > 0)
            //{
            //    Console.WriteLine(string.Format("{0}插入{1}条数据用时:{2}毫秒,平均每条耗时{3}毫秒", test.TestName, insertNum, _watch.ElapsedMilliseconds, _watch.ElapsedMilliseconds / insertNum));
            //}

            //return;

            #region 测试各种数据访问
            ////查询
            //_watch.Restart();
            //int mapNum = 0;
            //for (int i = 0; i < selectNum; i++)
            //{
            //    //test.InsertData(1);
            //    mapNum = test.GetData(1);
            //}
            ////test.BulkCopy();
            //_watch.Stop();
            //Console.WriteLine(string.Format("{0}查询测试:映射{1}条数据,执行{2}次总耗时{3}毫秒,平均耗时{4}毫秒", test.TestName, mapNum, selectNum, _watch.ElapsedMilliseconds, _watch.ElapsedMilliseconds / selectNum));
            #endregion

            #region 测试Json扩展方法
            //ResultJson res = new ResultJson()
            //{
            //    code = 1,
            //    message = "操作成功"
            //};
            //var jsonStr = JsonExtension.ToJson(res);
            //Console.WriteLine(jsonStr);
            #endregion

            #region 测试枚举扩展方法
            //var str = EnumTest.Create.ToDescription();
            //Console.WriteLine(str);
            #endregion

            //LogHelper.Test();
            //LogHelper.Info("ASASAS");
            _watch.Restart();
            test.BulkCopy();
            _watch.Stop();
            Console.WriteLine(string.Format("耗时{0}毫秒", _watch.ElapsedMilliseconds));
        }
Esempio n. 14
0
        private void WriteTestResults(StreamWriter testResults, IPerformanceTest test, bool withHeader, string techniqueName, int repeatNumber)
        {
            var data = test.GetPerFrameData();

            if (data.Count < 1)
            {
                return;
            }

            var variableNames = data.Keys.ToList();

            if (withHeader)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(variableNames[0]);
                for (int i = 1; i < variableNames.Count; i++)
                {
                    sb.Append($",{variableNames[i]}");
                }
                sb.Append($",Technique");
                sb.Append($",RepeatNumber");
                testResults.WriteLine(sb.ToString());
            }

            List <List <string> > variableData = new List <List <string> >(variableNames.Count);

            for (int i = 0; i < variableNames.Count; i++)
            {
                variableData.Add(data[variableNames[i]]);
            }

            //All data must be the same length
            var length = variableData[0].Count;

            for (int i = 0; i < length; i++)
            {
                StringBuilder line = new StringBuilder();
                line.Append($"{variableData[0][i]}");
                for (int j = 1; j < variableData.Count; j++)
                {
                    line.Append($",{variableData[j][i]}");
                }

                line.Append($",{techniqueName}");
                line.Append($",{repeatNumber}");

                testResults.WriteLine(line.ToString());
            }
        }
Esempio n. 15
0
        // On my system the result compared to classic implementation is:
        // Commit 0dca2387: 5 times slower, on average 2.2 µs per cal
        // Commit dcdf4581: 31 times slower, on average 1.71 µs per cal
        public void PerformanceTestSetValue()
        {
            IPerformanceTest classic = new Classic {
                Name = "Name"
            };
            IPerformanceTest newWay = factory.Create();

            newWay.Name = "Name";
            const int callCount1 = 10000000;
            const int callCount2 = 300000;

            PerformanceTest(
                () => classic.Name = "Name", callCount1,
                () => newWay.Name  = "Name", callCount2);
        }
Esempio n. 16
0
        public static Tuple <long, long> Run(IPerformanceTest test)
        {
            test.Before();
            _stopwatch.Reset();
            var bytesBefore = MemoryHelper.GetMemoryStats(MemoryHelper.CurProcess);

            _stopwatch.Start();
            test.Run();
            _stopwatch.Stop();
            var bytesAfter = MemoryHelper.GetMemoryStats(MemoryHelper.CurProcess);
            // only GC memory shows some differences...
            long memoryDiff = bytesAfter[0] - bytesBefore[0];

            return(new Tuple <long, long>(_stopwatch.ElapsedMilliseconds, memoryDiff));
        }
Esempio n. 17
0
        private Action TestToAction(IPerformanceTest test, Barrier barrier, IPerformanceTestRunnerListener listener)
        {
            return(() =>
            {
                if (!barrier.SignalAndWait(BarrierWaitTimeout))
                {
                    throw new TestFirstException("Timed out waiting for 'Invoke' barrier");
                }
                var testListener = new TestListenerAdapter(listener, new PerformanceSuite.PerfTestContext {
                    AgentId = "0", MachineId = Environment.MachineName
                });
                test.InvokeTest(testListener);

                if (!barrier.SignalAndWait(BarrierWaitTimeout))
                {
                    throw new TestFirstException("Timed out waiting for 'AfterInvokeInTestThread' barrier");
                }
            });
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            FluentTagBuilder systemDetails = new FluentTagBuilder("div");

            try {
                // I don't know enough about WMI yet to trust this code running well outside my own machine. Omitting these details if we have any exceptions.
                FluentTagBuilder ul = new FluentTagBuilder("ul");
                foreach (ManagementObject mo in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get())
                {
                    // Gleaned mostly from a StackOverflow question: http://stackoverflow.com/a/2670568/48700.
                    Console.WriteLine(mo["Name"]);
                    Console.WriteLine("\tCores: " + mo["NumberOfCores"]);
                    Console.WriteLine("\tCurrent Clock Speed: " + mo["CurrentClockSpeed"]);
                    Console.WriteLine("\tMax Clock Speed: " + mo["MaxClockSpeed"]);
                    ul.AddChild(new FluentTagBuilder("li", mo["Name"].ToString()).AddChild("ul", new[] { new FluentTagBuilder("li", "Cores: " + mo["NumberOfCores"]),
                                                                                                         new FluentTagBuilder("li", "Current Clock Speed: " + mo["CurrentClockSpeed"]),
                                                                                                         new FluentTagBuilder("li", "Max Clock Speed: " + mo["MaxClockSpeed"]) }));
                }
                systemDetails.AddChild(ul);
            }
            catch {
                systemDetails.AddChild(new FluentTagBuilder("p").WithText("Failed to retrieve system details."));
            }

            IEnumerable <Type>            tests         = Assembly.GetExecutingAssembly().GetTests();
            List <PerformanceTestSummary> testSummaries = new List <PerformanceTestSummary>();

            foreach (Type testType in tests)
            {
                IPerformanceTest test = (IPerformanceTest)testType.GetConstructor(Type.EmptyTypes).Invoke((object[])null);
                testSummaries.Add(test.Run());
            }
            List <FluentTagBuilder> resultHtmlContent = new List <FluentTagBuilder>()
            {
                systemDetails
            };

            foreach (PerformanceTestSummary testSummary in testSummaries)
            {
                FluentTagBuilder table = new FluentTagBuilder("table").AddChild("caption", string.Format("\"{0}\" ({1})", testSummary.Title, testSummary.Caption))
                                         .AddChild("tr", new[] { new FluentTagBuilder("th", "Average"),
                                                                 new FluentTagBuilder("th", "Method"),
                                                                 new FluentTagBuilder("th", "Ratio") });
                Console.WriteLine("--------------------");
                Console.WriteLine(testSummary.Title);
                Console.WriteLine("--------------------");
                double worstAverage = testSummary.Results.Max(result => result.ElapsedTicksCollection.Average());
                foreach (Tuple <PerformanceTestCandidateResult, double> resultAndAverage in testSummary.Results.Select(result => new Tuple <PerformanceTestCandidateResult, double>(result, result.ElapsedTicksCollection.Average())).OrderBy(tuple => tuple.Item2))
                {
                    string ratio = string.Format("{0:0.0}X", worstAverage / resultAndAverage.Item2);
                    table.AddChild("tr", new[] { new FluentTagBuilder("td", string.Format("{0} ticks", resultAndAverage.Item2.ToString("N"))),
                                                 new FluentTagBuilder("td", resultAndAverage.Item1.Title),
                                                 new FluentTagBuilder("td", ratio) });
                    Console.WriteLine("{0}: {1} average ticks (over {2} runs), {3}", resultAndAverage.Item1.Title, resultAndAverage.Item2.ToString("N"), testSummary.Iterations, ratio);
                }
                resultHtmlContent.Add(table);
            }
            // HTML results used, manually, to generate markup for README.markdown.
            string results = FluentTagBuilder.MakeIntoHtml5Page("Results", resultHtmlContent.ToArray());

            File.WriteAllText(Environment.CurrentDirectory + Path.DirectorySeparatorChar + "output.html", results, Encoding.UTF8);
            Console.ReadKey();
        }
Esempio n. 19
0
 public PerformanceTestIterator(int iterations, IPerformanceTest test)
 {
     this.iterations = iterations;
     this.test       = test;
 }
Esempio n. 20
0
 public PerformanceTestInitializer(IPerformanceTest test)
 {
     this.test = test;
 }
Esempio n. 21
0
 public TestResultItem(IPerformanceTest frame)
 {
     Framework = frame;
 }
Esempio n. 22
0
 private static TestResult RunPerformanceTests(IPerformanceTest performanceTest, int count, string testCase,
                                               RegistrationKind registrationKind)
 {
     WarmUpPerformanceTest(performanceTest, testCase, registrationKind);
     return(performanceTest.RunTest(count, testCase, registrationKind));
 }
Esempio n. 23
0
 public static string ToTestStringDefault(this IPerformanceTest self)
 {
     return(self.GetType().Name);
 }
Esempio n. 24
0
 public FormatClass(IPerformanceTest main)
 {
     this.main = main;
 }
Esempio n. 25
0
 private static void WarmUpPerformanceTest(IPerformanceTest performanceTest, string testCase,
                                           RegistrationKind registrationKind)
 {
     performanceTest.RunTest(1, testCase, registrationKind);
 }
Esempio n. 26
0
 public Builder Test(IPerformanceTest test)
 {
     m_tests.Add(test);
     return(this);
 }
 private void Awake()
 {
     performanceTest = InitView();
 }
Esempio n. 28
0
 public void SetPerformanceTest(ref IPerformanceTest performanceTest)
 {
     PerformanceTest = performanceTest;
 }