原因
Bench***rkDotNet支持将性能测试结果导出为各种格式,常用的html/csv。事实上,Bench***rkDotNet支持生成许多文件格式。
支持的文件格式:
支持的文件格式:
Bench***rkDotNet支持多种文件的生成。
Bench***rkDotNet依靠R来生成图表。Bench***rkDotNet只生成R的脚本文件,需要R执行脚本生成图表。
试验码
using System.Runtime.CompilerServices;using Bench***rkDotNet.Attributes;using Bench***rkDotNet.Configs;using Bench***rkDotNet.Exporters;using Bench***rkDotNet.Exporters.Csv;namespace dotnet_perf{ [RPlotExporter] //生成r脚本文件 [MemoryDiagnoser] [DisassemblyDiagnoser(printSource: true)] [Config(typeof(Config))] public class MethodInlineTest { [Params(10000)] public int Count { get; set; } public Random Random = new Random(); [Bench***rk] public void AggressiveInlining() { for (int i = 0; i < Count; i++) { int a = Random.Next(1, 100); int b = Random.Next(1, 100); int c = AggressiveInliningTest(a, b); } } [Bench***rk] public void AggressiveOptimization() { for (int i = 0; i < Count; i++) { int a = Random.Next(1, 100); int b = Random.Next(1, 100); int c = AggressiveOptimizationTest(a, b); } } [Bench***rk] public void NoInlining() { for (int i = 0; i < Count; i++) { int a = Random.Next(1, 100); int b = Random.Next(1, 100); int c = NoInliningnTest(a, b); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int AggressiveInliningTest(int a, int b) //求数的大小 { return a > b ? a : b; } [MethodImpl(MethodImplOptions.AggressiveOptimization)] public int AggressiveOptimizationTest(int a, int b) //求数的大小 { return a > b ? a : b; } [MethodImpl(MethodImplOptions.NoInlining)] public int NoInliningnTest(int a, int b) //求数的大小 { return a > b ? a : b; } private class Config : ManualConfig { public Config() { AddExporter(CsvMeasurementsExporter.Default); //生成csv文件,r脚本生成图表需要 AddExporter(RPlotExporter.Default); //使用r默认的配置 } } }}#执行R脚本Rscript.exe .BuildPlots.R
看Bench***rkDotNet生成的图表。
Bench***rkDotNet 生成图1
Bench***rkDotNet生成图1
Bench***rkDotNet生成图2
本文来自玩味不尽投稿,不代表舒华文档立场,如若转载,请注明出处:https://www.chinashuhua.cn/24/647492.html