public static void Main(string[] parameters)
        {
            foreach (var platform in Directory.GetDirectories("."))
            {
                foreach (var os in Directory.GetDirectories(platform))
                {
                    var files = Directory.GetFiles(os, "*.Results.xml");
                    if (files.Length == 0)
                    {
                        continue;
                    }

                    var libraryNames = files.Select(x => x.Remove(x.Length - 12)).ToArray();
                    var results      = files.Select(x => PerformanceTestResult.Load(x)).ToArray();

                    var categories = results.SelectMany(x => x.Entries).Select(x => x.Name).Distinct().ToArray();

                    using (var htmlWriter = new StreamWriter(Path.Combine(os, "TestResults.htm")))
                        using (var wikiWriter = new StreamWriter(Path.Combine(os, "TestResults.wiki")))
                        {
                            htmlWriter.WriteLine("<html><body>");
                            foreach (var category in categories)
                            {
                                var entries = results.Select(x => new { Entry = x[category], Name = x.AssemblyName }).OrderByDescending(x => x.Name).ToArray();

                                var performanceValues = entries.Select(x => x.Entry == null ? 0 : ( double )x.Entry.Score).ToArray();
                                var maximumValue      = performanceValues.Max();
                                var normalizedValues  = performanceValues.Select(x => (x * 100.0 / maximumValue).ToString(CultureInfo.InvariantCulture)).ToArray();

                                var url = string.Format(@"http://chart.apis.google.com/chart?chtt={5}&chts=000000,12&chs=1000x120&chf=bg,s,ffffff|c,s,ffffff&chxt=x,y&chxl=1:||0:|0|{1}|{2}|{3}&cht=bhg&chd=t:{4}&chdl={0}&chco=cc0000,003399,ff00cc,cc6600&chbh=10&nonsense=something_that_ends_with.png", string.Join("|", entries.Select(x => x.Name).ToArray()), ( long )(maximumValue / 3), ( long )(maximumValue * 2 / 3), maximumValue, string.Join("|", normalizedValues), Escape(category));

                                htmlWriter.WriteLine(@"<img src=""{0}""/>", url);
                                wikiWriter.WriteLine("{0}", url);
                            }
                            htmlWriter.WriteLine("</body></html>");
                        }
                }
            }
        }
Ejemplo n.º 2
0
        public void TestAll(Assembly testedAssembly)
        {
            Console.WriteLine("{0} v{1} results:", testedAssembly.GetName().Name, testedAssembly.GetName().Version);

            var testResult = new PerformanceTestResult();

            testResult.AssemblyName = testedAssembly.GetName().Name.Split('.').First();

            Action <string, double> addEntry = (name, score) => { testResult.Entries.Add(new PerformanceEntry(name, score)); };

            OnPerformanceReport += addEntry;

            var methodsToTest = new Action <int>[] {
                TestInvocation,
                TestAllocation,
                TestVarargMarshaling,
                TestExceptionHandlerOverhead,
                TestExceptionRethrow
            };

            var testNames = new string[] {
                Invocation,
                Allocation,
                VarargInvocations,
                ExceptionHandlerOverhead,
                ExceptionRethrows
            };

            var perSecond = new bool[] {
                true,
                true,
                true,
                true,
                true,
            };

            try
            {
                // JITting code
                for (int i = 0; i < methodsToTest.Length; i++)
                {
                    _timer.Start();

                    OnBeginTest();
                    try { methodsToTest[i](Iterations); }
                    catch (NotImplementedException) { }
                    OnEndTest();
                    GC.Collect();

                    _timer.Stop();
                    _timer.Reset();
                }

                // run tests
                for (int i = 0; i < methodsToTest.Length; i++)
                {
                    var bestResult = double.MaxValue;
                    for (int j = 0; j < Runnings; j++)
                    {
                        OnBeginTest();
                        try
                        {
                            _timer.Start();
                            methodsToTest[i](Iterations);
                            _timer.Stop();
                        }
                        catch (NotImplementedException) { goto end_test; }
                        finally
                        {
                            OnEndTest();
                            GC.Collect();
                        }

                        bestResult = Math.Min(bestResult, _timer.Elapsed.TotalMilliseconds);
                        _timer.Reset();
                    }

                    OnPerformanceReport(testNames[i], perSecond[i] ? ( long )(1000.0 * Iterations / bestResult) : bestResult);

end_test:
                    continue;
                }

                GC.Collect();
                OnPerformanceReport(TotalManagedMemory, GC.GetTotalMemory(true) / 1024.0);

                GC.Collect();
                OnPerformanceReport(TotalUnmanagedMemory, OS.GetTaskBasicInfo().resident_size.ToInt32() / 1024);
            }
            finally
            {
                OnPerformanceReport -= addEntry;
            }
            Console.WriteLine();

            var osdir = "";

            switch (OS.Version)
            {
            case OS.MacOSVersion.Tiger: osdir = "Tiger"; break;

            case OS.MacOSVersion.Leopard: osdir = "Leopard"; break;

            case OS.MacOSVersion.SnowLeopard: osdir = "Snow Leopard"; break;
            }

            var resultsFile         = Assembly.GetExecutingAssembly().GetName().Name + ".Results.xml";
            var statisticsDirectory = PathCombine("..", "..", "results", BitConverter.IsLittleEndian ? "Intel" : "PowerPC", osdir);

            if (Directory.Exists(statisticsDirectory))
            {
                testResult.Save(Path.Combine(statisticsDirectory, resultsFile));
            }

            testResult.Save(resultsFile);
        }