mirror of https://github.com/SixLabors/ImageSharp
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
697 B
31 lines
697 B
// Copyright (c) Six Labors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
|