daily update on 20240206 by nitload youmu

This commit is contained in:
Nitload
2024-02-06 13:54:30 +08:00
parent 5d778e0f2f
commit 8548757bbf
114 changed files with 86620 additions and 752 deletions
+25 -65
View File
@@ -5,81 +5,41 @@ using System.Reflection;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BenchmarkDotNet.Jobs;
namespace BenchMark
{
internal class Program
internal unsafe class Program
{
static unsafe void Main(string[] args)
static void Main(string[] args)
{
int* p = (int*)Marshal.AllocHGlobal(sizeof(int) * 10);
for (int i = 0; i < 10; i++)
{
*(p + i) = i;
}
int[] array = (int[])GCHandle.FromIntPtr((IntPtr)p).Target;
Console.WriteLine(array);
//BenchmarkRunner.Run(typeof(MyClass).Assembly);
}
}
public class MyClass
{
[Benchmark]
public bool isM128Pinnable()
{
var type = typeof(M128);
foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
// 如果字段是引用类型,返回 false
if (!field.FieldType.IsValueType)
{
return false;
}
}
// 如果没有引用类型的字段,返回 true
return true;
}
[Benchmark]
public bool isVector4Pinnable()
{
var type = typeof(int);
foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
// 如果字段是引用类型,返回 false
if (!field.FieldType.IsValueType)
{
return false;
}
}
// 如果没有引用类型的字段,返回 true
return true;
Calculator c = new Calculator();
c.PtrSub();
var sum = BenchmarkRunner.Run(typeof(Calculator).Assembly);
}
}
[StructLayout(LayoutKind.Explicit)]
public unsafe struct M128
public struct Calculator
{
[FieldOffset(0)] internal fixed float Single[4];
[FieldOffset(0)] internal fixed double Double[2];
public static int Sub(int left, int right)
{
return left - right;
}
[FieldOffset(0)] internal fixed sbyte Int8[16];
[FieldOffset(0)] internal fixed short Int16[8];
[FieldOffset(0)] internal fixed int Int32[4];
[FieldOffset(0)] internal fixed long Int64[2];
[FieldOffset(0)] internal fixed byte UInt8[16];
[FieldOffset(0)] internal fixed ushort UInt16[8];
[FieldOffset(0)] internal fixed uint UInt32[4];
[FieldOffset(0)] internal fixed ulong UInt64[2];
[Benchmark]
public unsafe void DeleSub()
{
Func<int, int, int> SubDele = Sub;
SubDele(1, 0);
}
[Benchmark]
public unsafe void PtrSub()
{
delegate*<int, int, int> SubPtr = &Sub;
SubPtr(1, 0);
}
}
}