45 lines
980 B
C#
45 lines
980 B
C#
using BenchmarkDotNet.Running;
|
|
using BenchmarkDotNet.Attributes;
|
|
using System.Runtime.InteropServices;
|
|
using System.Reflection;
|
|
using System.Numerics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.Versioning;
|
|
using BenchmarkDotNet.Jobs;
|
|
|
|
namespace BenchMark
|
|
{
|
|
internal unsafe class Program
|
|
{
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Calculator c = new Calculator();
|
|
c.PtrSub();
|
|
var sum = BenchmarkRunner.Run(typeof(Calculator).Assembly);
|
|
}
|
|
}
|
|
|
|
|
|
public struct Calculator
|
|
{
|
|
public static int Sub(int left, int right)
|
|
{
|
|
return left - right;
|
|
}
|
|
|
|
[Benchmark]
|
|
public unsafe void DeleSub()
|
|
{
|
|
Func<int, int, int> SubDele = Sub;
|
|
SubDele(1, 0);
|
|
}
|
|
|
|
[Benchmark]
|
|
public unsafe void PtrSub()
|
|
{
|
|
delegate*<int, int, int> SubPtr = ⋐
|
|
SubPtr(1, 0);
|
|
}
|
|
}
|
|
} |