<kbd id="5sdj3"></kbd>
<th id="5sdj3"></th>

  • <dd id="5sdj3"><form id="5sdj3"></form></dd>
    <td id="5sdj3"><form id="5sdj3"><big id="5sdj3"></big></form></td><del id="5sdj3"></del>

  • <dd id="5sdj3"></dd>
    <dfn id="5sdj3"></dfn>
  • <th id="5sdj3"></th>
    <tfoot id="5sdj3"><menuitem id="5sdj3"></menuitem></tfoot>

  • <td id="5sdj3"><form id="5sdj3"><menu id="5sdj3"></menu></form></td>
  • <kbd id="5sdj3"><form id="5sdj3"></form></kbd>

    BenchmarkDotNet性能測試

    共 11693字,需瀏覽 24分鐘

     ·

    2021-06-16 10:07


    BenchmarkDotNet是一款開源的性能測試工具,使用方式非常簡單,特別是對實現(xiàn)同一功能的兩種方式,猶豫不決時,可以使用它進(jìn)行個對比。

    比如我們比較ADO.NET方式查詢數(shù)據(jù)庫表,和用Dapper方式獲取數(shù)據(jù)為表,只需要在兩個方法上增加 [Benchmark]就可以了,然后調(diào)用var summary = BenchmarkRunner.Run<Cycle>();就實現(xiàn)了性能測試。

    using System;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Security.Cryptography;using BenchmarkDotNet.Attributes;using BenchmarkDotNet.Running;using Dapper;
    namespace MyBenchmarks{ public class Product { public string Name { get; set; } public string ProductNumber { get; set; } public bool MakeFlag { get; set; } public bool FinishedGoodsFlag { get; set; } public string Color { get; set; } public short SafetyStockLevel { get; set; } public short ReorderPoint { get; set; } public decimal StandardCost { get; set; } public decimal ListPrice { get; set; } public string Size { get; set; } public string SizeUnitMeasureCode { get; set; } public string WeightUnitMeasureCode { get; set; } public double Weight { get; set; } public int DaysToManufacture { get; set; } public string ProductLine { get; set; } public string Class { get; set; } public string Style { get; set; } public int ProductSubcategoryID { get; set; } public int ProductModelID { get; set; } public DateTime SellStartDate { get; set; } public DateTime SellEndDate { get; set; } public DateTime DiscontinuedDate { get; set; } public Guid rowguid { get; set; } public DateTime ModifiedDate { get; set; }

    } public class Cycle {
    [Benchmark] public void DapperTest() { var conn = new SqlConnection("Data Source=.;Initial Catalog=AdventureWorks2016;Persist Security Info=True;User ID=sa;password=sa;"); var table = conn.Query<Product>("select top 100 * from production.product"); } [Benchmark] public void CommandTest() { var conn = "Data Source=.;Initial Catalog=AdventureWorks2016;Persist Security Info=True;User ID=sa;password=sa;"; var sql = "select top 100 * from production.product"; var dapp = new SqlDataAdapter(sql, conn); var table = new DataTable(); dapp.Fill(table); } }
    public class Program { public static void Main(string[] args) { var summary = BenchmarkRunner.Run<Cycle>(); } }}

    運行一下看一下結(jié)果,為了減少篇幅,刪除了一些結(jié)果,從結(jié)果看出,為了得到較為客觀的性能測試結(jié)果,BenchmarkDotNet還是做了很多工作的:

    OverheadJitting,WorkloadJitting,WorkloadPilot,OverheadWarmup,OverheadActual,WorkloadWarmup,WorkloadActual,WorkloadResult。

    并且通過最后的一個表格,清楚的給出了結(jié)果。同時還給出了Warnings ,以供參考。

    // Validating benchmarks:// ***** BenchmarkRunner: Start   *****// ***** Found 2 benchmark(s) in total *****// ***** Building 1 exe(s) in Parallel: Start   *****// start dotnet restore  /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\MyFile\Source\Repos\Asp.NetCoreExperiment\Asp.NetCoreExperiment\BenchmarkDotNet\Demo01\bin\Release\net6.0\03bf0209-ac26-4de1-b763-4ba03e46cf4d// command took 2.83s and exited with 0// start dotnet build -c Release  --no-restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\MyFile\Source\Repos\Asp.NetCoreExperiment\Asp.NetCoreExperiment\BenchmarkDotNet\Demo01\bin\Release\net6.0\03bf0209-ac26-4de1-b763-4ba03e46cf4d// command took 4.29s and exited with 0// ***** Done, took 00:00:07 (7.52 sec)   *****// Found 2 benchmarks://   Cycle.DapperTest: DefaultJob//   Cycle.CommandTest: DefaultJob
    // **************************// Benchmark: Cycle.DapperTest: DefaultJob// *** Execute ***// Launch: 1 / 1// Execute: dotnet "03bf0209-ac26-4de1-b763-4ba03e46cf4d.dll" --benchmarkName "MyBenchmarks.Cycle.DapperTest" --job "Default" --benchmarkId 0 in C:\MyFile\Source\Repos\Asp.NetCoreExperiment\Asp.NetCoreExperiment\BenchmarkDotNet\Demo01\bin\Release\net6.0\03bf0209-ac26-4de1-b763-4ba03e46cf4d\bin\Release\net6.0// BeforeAnythingElse
    // Benchmark Process Environment Information:// Runtime=.NET 6.0.0 (6.0.21.25307), X64 RyuJIT// GC=Concurrent Workstation// Job: DefaultJob
    OverheadJitting 1: 1 op, 229700.00 ns, 229.7000 us/opWorkloadJitting 1: 1 op, 410021000.00 ns, 410.0210 ms/op
    WorkloadWarmup 1: 1 op, 4581600.00 ns, 4.5816 ms/opWorkloadWarmup 2: 1 op, 746500.00 ns, 746.5000 us/opWorkloadWarmup 3: 1 op, 830000.00 ns, 830.0000 us/opWorkloadWarmup 4: 1 op, 822900.00 ns, 822.9000 us/opWorkloadWarmup 5: 1 op, 741800.00 ns, 741.8000 us/opWorkloadWarmup 6: 1 op, 746900.00 ns, 746.9000 us/opWorkloadWarmup 7: 1 op, 826300.00 ns, 826.3000 us/opWorkloadWarmup 8: 1 op, 698300.00 ns, 698.3000 us/op
    // BeforeActualRunWorkloadActual 1: 1 op, 755100.00 ns, 755.1000 us/op……WorkloadActual 100: 1 op, 712700.00 ns, 712.7000 us/op
    // AfterActualRunWorkloadResult 1: 1 op, 755100.00 ns, 755.1000 us/op……WorkloadResult 95: 1 op, 712700.00 ns, 712.7000 us/op
    // AfterAll// Benchmark Process 26724 has exited with code 0
    Mean = 753.054 us, StdErr = 11.687 us (1.55%), N = 95, StdDev = 113.909 usMin = 578.400 us, Q1 = 668.600 us, Median = 734.900 us, Q3 = 798.800 us, Max = 1,052.600 usIQR = 130.200 us, LowerFence = 473.300 us, UpperFence = 994.100 usConfidenceInterval = [713.353 us; 792.754 us] (CI 99.9%), Margin = 39.701 us (5.27% of Mean)Skewness = 0.87, Kurtosis = 2.93, MValue = 3.63
    // **************************// Benchmark: Cycle.CommandTest: DefaultJob// *** Execute ***// Launch: 1 / 1// Execute: dotnet "03bf0209-ac26-4de1-b763-4ba03e46cf4d.dll" --benchmarkName "MyBenchmarks.Cycle.CommandTest" --job "Default" --benchmarkId 1 in C:\MyFile\Source\Repos\Asp.NetCoreExperiment\Asp.NetCoreExperiment\BenchmarkDotNet\Demo01\bin\Release\net6.0\03bf0209-ac26-4de1-b763-4ba03e46cf4d\bin\Release\net6.0// BeforeAnythingElse
    // Benchmark Process Environment Information:// Runtime=.NET 6.0.0 (6.0.21.25307), X64 RyuJIT// GC=Concurrent Workstation// Job: DefaultJob
    OverheadJitting 1: 1 op, 215400.00 ns, 215.4000 us/opWorkloadJitting 1: 1 op, 339247500.00 ns, 339.2475 ms/op
    WorkloadWarmup 1: 1 op, 3680100.00 ns, 3.6801 ms/opWorkloadWarmup 2: 1 op, 943000.00 ns, 943.0000 us/opWorkloadWarmup 3: 1 op, 875200.00 ns, 875.2000 us/opWorkloadWarmup 4: 1 op, 982500.00 ns, 982.5000 us/opWorkloadWarmup 5: 1 op, 956900.00 ns, 956.9000 us/opWorkloadWarmup 6: 1 op, 1030800.00 ns, 1.0308 ms/opWorkloadWarmup 7: 1 op, 1170900.00 ns, 1.1709 ms/opWorkloadWarmup 8: 1 op, 1169400.00 ns, 1.1694 ms/op
    // BeforeActualRunWorkloadActual 1: 1 op, 975400.00 ns, 975.4000 us/op……WorkloadActual 100: 1 op, 897400.00 ns, 897.4000 us/op
    // AfterActualRunWorkloadResult 1: 1 op, 975400.00 ns, 975.4000 us/op……WorkloadResult 91: 1 op, 897400.00 ns, 897.4000 us/op
    // AfterAll// Benchmark Process 17300 has exited with code 0
    Mean = 951.263 us, StdErr = 13.676 us (1.44%), N = 91, StdDev = 130.465 usMin = 759.300 us, Q1 = 864.000 us, Median = 912.900 us, Q3 = 1,004.600 us, Max = 1,316.000 usIQR = 140.600 us, LowerFence = 653.100 us, UpperFence = 1,215.500 usConfidenceInterval = [904.736 us; 997.789 us] (CI 99.9%), Margin = 46.526 us (4.89% of Mean)Skewness = 0.95, Kurtosis = 3.05, MValue = 2.44
    // ***** BenchmarkRunner: Finish *****
    // * Export * BenchmarkDotNet.Artifacts\results\MyBenchmarks.Cycle-report.csv BenchmarkDotNet.Artifacts\results\MyBenchmarks.Cycle-report-github.md BenchmarkDotNet.Artifacts\results\MyBenchmarks.Cycle-report.html
    // * Detailed results *Cycle.DapperTest: DefaultJobRuntime = .NET 6.0.0 (6.0.21.25307), X64 RyuJIT; GC = Concurrent WorkstationMean = 753.054 us, StdErr = 11.687 us (1.55%), N = 95, StdDev = 113.909 usMin = 578.400 us, Q1 = 668.600 us, Median = 734.900 us, Q3 = 798.800 us, Max = 1,052.600 usIQR = 130.200 us, LowerFence = 473.300 us, UpperFence = 994.100 usConfidenceInterval = [713.353 us; 792.754 us] (CI 99.9%), Margin = 39.701 us (5.27% of Mean)Skewness = 0.87, Kurtosis = 2.93, MValue = 3.63-------------------- Histogram --------------------[ 545.635 us ; 582.035 us) | @[ 582.035 us ; 650.935 us) | @@@@@@@@@@@@@@@[ 650.935 us ; 726.135 us) | @@@@@@@@@@@@@@@@@@@@@@@@@@@[ 726.135 us ; 791.665 us) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@[ 791.665 us ; 852.365 us) | @@@@@@@@[ 852.365 us ; 924.365 us) | @@@[ 924.365 us ; 1,009.685 us) | @@@@@@@@@@@[1,009.685 us ; 1,085.365 us) | @@---------------------------------------------------
    Cycle.CommandTest: DefaultJobRuntime = .NET 6.0.0 (6.0.21.25307), X64 RyuJIT; GC = Concurrent WorkstationMean = 951.263 us, StdErr = 13.676 us (1.44%), N = 91, StdDev = 130.465 usMin = 759.300 us, Q1 = 864.000 us, Median = 912.900 us, Q3 = 1,004.600 us, Max = 1,316.000 usIQR = 140.600 us, LowerFence = 653.100 us, UpperFence = 1,215.500 usConfidenceInterval = [904.736 us; 997.789 us] (CI 99.9%), Margin = 46.526 us (4.89% of Mean)Skewness = 0.95, Kurtosis = 3.05, MValue = 2.44-------------------- Histogram --------------------[ 721.230 us ; 780.280 us) | @@[ 780.280 us ; 860.730 us) | @@@@@@@@@@@@@@@@@@@@[ 860.730 us ; 936.870 us) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ 936.870 us ; 1,020.120 us) | @@@@@@@@@@@@@@@@[1,020.120 us ; 1,080.630 us) | @@@@@[1,080.630 us ; 1,170.980 us) | @@@@@@@[1,170.980 us ; 1,247.120 us) | @@@@@@@@[1,247.120 us ; 1,277.930 us) |[1,277.930 us ; 1,354.070 us) | @---------------------------------------------------
    // * Summary *
    BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19043.1052 (21H1/May2021Update)Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores.NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT [AttachedDebugger] DefaultJob : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT

    | Method | Mean | Error | StdDev | Median ||------------ |---------:|---------:|---------:|---------:|| DapperTest | 753.1 us | 39.70 us | 113.9 us | 734.9 us || CommandTest | 951.3 us | 46.53 us | 130.5 us | 912.9 us |
    // * Warnings *MultimodalDistribution Cycle.DapperTest: Default -> It seems that the distribution is bimodal (mValue = 3.63)Environment Summary -> Benchmark was executed with attached debuggerMinIterationTime Cycle.DapperTest: Default -> The minimum observed iteration time is 578.4000 us which is very small. It's recommended to increase it to at least 100.0000 ms using more operations. Cycle.CommandTest: Default -> The minimum observed iteration time is 759.3000 us which is very small. It's recommended to increase it to at least 100.0000 ms using more operations.
    // * Hints *Outliers Cycle.DapperTest: Default -> 5 outliers were removed (1.06 ms..2.17 ms) Cycle.CommandTest: Default -> 9 outliers were removed (1.37 ms..2.51 ms)
    // * Legends * Mean : Arithmetic mean of all measurements Error : Half of 99.9% confidence interval StdDev : Standard deviation of all measurements Median : Value separating the higher half of all measurements (50th percentile) 1 us : 1 Microsecond (0.000001 sec)
    // ***** BenchmarkRunner: End *****// ** Remained 0 benchmark(s) to run **Run time: 00:00:03 (3.12 sec), executed benchmarks: 2
    Global total time: 00:00:10 (10.65 sec), executed benchmarks: 2// * Artifacts cleanup *



    往期精彩回顧




    【推薦】.NET Core開發(fā)實戰(zhàn)視頻課程 ★★★

    .NET Core實戰(zhàn)項目之CMS 第一章 入門篇-開篇及總體規(guī)劃

    【.NET Core微服務(wù)實戰(zhàn)-統(tǒng)一身份認(rèn)證】開篇及目錄索引

    Redis基本使用及百億數(shù)據(jù)量中的使用技巧分享(附視頻地址及觀看指南)

    .NET Core中的一個接口多種實現(xiàn)的依賴注入與動態(tài)選擇看這篇就夠了

    10個小技巧助您寫出高性能的ASP.NET Core代碼

    用abp vNext快速開發(fā)Quartz.NET定時任務(wù)管理界面

    在ASP.NET Core中創(chuàng)建基于Quartz.NET托管服務(wù)輕松實現(xiàn)作業(yè)調(diào)度

    現(xiàn)身說法:實際業(yè)務(wù)出發(fā)分析百億數(shù)據(jù)量下的多表查詢優(yōu)化

    關(guān)于C#異步編程你應(yīng)該了解的幾點建議

    C#異步編程看這篇就夠了


    瀏覽 39
    點贊
    評論
    收藏
    分享

    手機(jī)掃一掃分享

    分享
    舉報
    評論
    圖片
    表情
    推薦
    點贊
    評論
    收藏
    分享

    手機(jī)掃一掃分享

    分享
    舉報

    <kbd id="5sdj3"></kbd>
    <th id="5sdj3"></th>

  • <dd id="5sdj3"><form id="5sdj3"></form></dd>
    <td id="5sdj3"><form id="5sdj3"><big id="5sdj3"></big></form></td><del id="5sdj3"></del>

  • <dd id="5sdj3"></dd>
    <dfn id="5sdj3"></dfn>
  • <th id="5sdj3"></th>
    <tfoot id="5sdj3"><menuitem id="5sdj3"></menuitem></tfoot>

  • <td id="5sdj3"><form id="5sdj3"><menu id="5sdj3"></menu></form></td>
  • <kbd id="5sdj3"><form id="5sdj3"></form></kbd>
    国产欧美日韩A V片 | 超碰在线97免费 | 先锋影音麻豆资源 | 真人操逼视频 | 日本黄色一区二区三区 |