dotnet/BenchmarkDotNet

Custom sinks

开放

#252 创建于 2016年8月25日

 (6 条评论) (2 个反应) (0 位负责人)C# (1,063 个派生)batch import
enhancementhelp wantedup-for-grabs

仓库指标

星标
 (11,480 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

It is nice to put the results from benchmark runs in version control so that perf can be tracked over time. Currently I hack it like this:

    using System.Collections.Generic;
    using System.IO;
    using BenchmarkDotNet.Reports;
    using BenchmarkDotNet.Running;

    public class Program
    {
        private static readonly string DesinationDirectory = System.IO.Path.Combine(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "Results");

        public static void Main()
        {
            foreach (var summary in RunAll())
            {
                CopyResult(summary.Title);
            }
        }

        private static IEnumerable<Summary> RunAll()
        {
            ClearAllResults();
            var switcher = new BenchmarkSwitcher(typeof(Program).Assembly);
            var summaries = switcher.Run(new[] { "*" });
            return summaries;
        }

        private static IEnumerable<Summary> RunSingle<T>()
        {
            var summaries = new[] { BenchmarkRunner.Run<T>() };
            return summaries;
        }

        private static void CopyResult(string name)
        {
#if DEBUG
#else
            var sourceFileName = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Artifacts", "results", name + "-report-github.md");
            System.IO.Directory.CreateDirectory(DesinationDirectory);
            var destinationFileName = System.IO.Path.Combine(DesinationDirectory, name + ".md");
            File.Copy(sourceFileName, destinationFileName, true);
#endif
        }

        private static void ClearAllResults()
        {
            if (Directory.Exists(DesinationDirectory))
            {
                foreach (var resultFile in Directory.EnumerateFiles(DesinationDirectory, "*.md"))
                {
                    File.Delete(resultFile);
                }
            }
        }
    }

贡献者指南