在更新BenchmarkDotNet源码时发现已经发布V0.13.2版本了,主要增加了这些特性:
BenchmarkDotNet v0.13.2新增功能
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
namespace CSharpBenchmarks.MathTest
{
[DisassemblyDiagnoser(printSource: true, maxDepth: 3)]
[MemoryDiagnoser]
// //提示不支持"Currently NativeAOT has no DisassemblyDiagnoser support"
[SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.NativeAot70)]
[HideColumns(Column.Gen2)] //隐藏GC2代列
public class RoundTest
{
[Params(1.5)]
public double Value { get; set; }
[Benchmark(Baseline = true)]
public double RoundDefault() => Math.Round(Value);
}
}
BechmarkDotNet显示更多更全的信息
还有对WebAssembly支持的越来越好,输出的信息更多更全,还有显示更多的汇编代码(在测试方法中调用的其他方法显示汇编代码):
//内联后生成的汇编代码,没有方法调用
//CSharpBenchmarks.MathTest.RoundTest.RoundDefault()
// public double RoundDefault() => Math.Round(Value);
// ^^^^^^^^^^^^^^^^^
vzeroupper
vroundsd xmm0,xmm0,qword ptr[rcx + 8],4
ret
; Total bytes of code 11
继续在测试方法中调用其他方法(汇编代码):
// net6perf.LinqTest.TakTest.Take()
// int sum = 0;
// ^^^^^^^^^^^^
// for (int i = 0; i < Times; i++)
// ^^^^^^^^^
// var array = bytes.Take(5).ToArray();
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// sum += array.Length;
// ^^^^^^^^^^^^^^^^^^^^
// return sum;
//^^^^^^^^^^^push r14
push rdi
push rsi
push rbp
push rbx
sub rsp,20
mov rsi, rcx
xor edi, edi
xor ebx, ebx
cmp dword ptr [rsi+10],0
jle near ptr M00_L03
M00_L00:
mov rbp,[rsi + 8]
test rbp, rbp
je near ptr M00_L04
mov rdx, rbp
mov rcx, offset MT_System.Linq.IPartition`1[[System.Int32, System.Private.CoreLib]]
//===========调用IsInstanceOfInterface方法===========
call qword ptr [System.Runtime.CompilerServices.CastHelpers.IsInstanceOfInterface(Void *, System.Object)]
test rax, rax
jne short M00_L01
mov rcx, offset MT_System.Linq.Enumerable+ListPartition`1[[System.Int32, System.Private.CoreLib]]
call CORINFO_HELP_NEWSFAST
mov r14, rax
call CORINFO_HELP_GETCURRENTMANAGEDTHREADID
mov [r14+8],eax
lea rcx,[r14 + 18]
mov rdx, rbp
call CORINFO_HELP_ASSIGN_REF
xor ecx, ecx
mov [r14+14],ecx
mov dword ptr [r14+20],4
jmp short M00_L02
M00_L01:
mov rcx, rax
mov r11,7FFE65150440
mov edx,5
call qword ptr [r11]
mov r14, rax
M00_L02:
mov rcx, r14
call qword ptr [System.Linq.Enumerable.ToArray[[System.Int32, System.Private.CoreLib]](System.Collections.Generic.IEnumerable`1 < Int32 >)]
add edi,[rax + 8]
inc ebx
cmp ebx,[rsi + 10]
jl near ptr M00_L00
M00_L03:
mov eax, edi
add rsp,20
pop rbx
pop rbp
pop rsi
pop rdi
pop r14
ret
M00_L04:
mov ecx,10
call qword ptr [7FFE65535780]
int 3
; Total bytes of code 191
//System.Runtime.CompilerServices.CastHelpers.IsInstanceOfInterface(Void *, System.Object)
test rdx, rdx
je short M01_L03
mov rax,[rdx]
movzx r8d, word ptr [rax+0E]
test r8, r8
je short M01_L02
mov r9,[rax + 38]
cmp r8,4
jl short M01_L01
M01_L00:
cmp[r9],rcx
je short M01_L03
cmp [r9+8],rcx
je short M01_L03
cmp [r9+10],rcx
je short M01_L03
cmp [r9+18],rcx
je short M01_L03
add r9,20
add r8,0FFFFFFFFFFFFFFFC
cmp r8,4
jge short M01_L00
test r8, r8
je short M01_L02
M01_L01:
cmp[r9],rcx
je short M01_L03
add r9,8
dec r8
test r8, r8
jg short M01_L01
M01_L02:
test dword ptr [rax],406C0000
jne short M01_L04
xor edx, edx
M01_L03:
mov rax, rdx
ret
M01_L04:
jmp qword ptr [System.Runtime.CompilerServices.CastHelpers.IsInstance_Helper(Void *, System.Object)]
; Total bytes of code 107
个人能力有限,如果您发现有什么不对,请私信我
如果您觉得对您有用的话,可以点个赞或者加个关注,欢迎大家一起进行技术交流
留言与评论(共有 0 条评论) “” |