📷 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.
 
 

31 lines
641 B

// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General;
public class StructCasting
{
[Benchmark(Baseline = true)]
public short ExplicitCast()
{
const 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()
{
int x = 5 * 2;
return Unsafe.As<int, short>(ref Unsafe.AsRef(ref x));
}
}