mirror of https://github.com/SixLabors/ImageSharp
5 changed files with 76 additions and 17 deletions
@ -0,0 +1,33 @@ |
|||
namespace ImageSharp.Benchmarks.General |
|||
{ |
|||
using System; |
|||
|
|||
using BenchmarkDotNet.Attributes; |
|||
|
|||
public class Abs |
|||
{ |
|||
[Params(-1, 1)] |
|||
public int X { get; set; } |
|||
|
|||
[Benchmark(Baseline = true, Description = "Maths Abs")] |
|||
public int MathAbs() |
|||
{ |
|||
int x = this.X; |
|||
return Math.Abs(x); |
|||
} |
|||
|
|||
[Benchmark(Description = "Conditional Abs")] |
|||
public int ConditionalAbs() |
|||
{ |
|||
int x = this.X; |
|||
return x < 0 ? -x : x; |
|||
} |
|||
|
|||
[Benchmark(Description = "Bitwise Abs")] |
|||
public int AbsBitwise() |
|||
{ |
|||
int x = this.X; |
|||
return (x ^ (x >> 31)) - (x >> 31); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue