📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
619 B

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General
{
public class StructCasting
{
[Benchmark(Baseline = true)]
public short ExplicitCast()
{
int x = 5 * 2;
return (short)x;
}
[Benchmark]
public short UnsafeCast()
{
int x = 5 * 2;
return Unsafe.As<int, short>(ref x);
}
[Benchmark]
public short UnsafeCastRef()
{
return Unsafe.As<int, short>(ref Unsafe.AsRef(5 * 2));
}
}
}