From 593107e190856b7059f9e32f7dcb1343ca057db7 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 20 Oct 2019 12:31:59 +0200 Subject: [PATCH] Multiplication is faster than bit shifting --- MediaBrowser.Common/Hex.cs | 2 +- benches/Jellyfin.Common.Benches/HexDecodeBenches.cs | 5 ++++- benches/Jellyfin.Common.Benches/Program.cs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Common/Hex.cs b/MediaBrowser.Common/Hex.cs index 6c86e4e6d..b2d9aea3a 100644 --- a/MediaBrowser.Common/Hex.cs +++ b/MediaBrowser.Common/Hex.cs @@ -81,7 +81,7 @@ namespace MediaBrowser.Common break; // Unreachable } - bytes[j] = (byte)((a << 4) | b); + bytes[j] = (byte)((a * 16) | b); } return bytes; diff --git a/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs b/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs index 2efe5273f..5cd47202c 100644 --- a/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs +++ b/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs @@ -9,7 +9,7 @@ namespace Jellyfin.Common.Benches [MemoryDiagnoser] public class HexDecodeBenches { - [Params(0, 10, 100, 1000, 10000, 1000000)] + [Params(/*0,*/ 10, 100, 1000, 10000, 1000000)] public int N { get; set; } private string data; @@ -40,6 +40,9 @@ namespace Jellyfin.Common.Benches public byte[] Decode() => Hex.Decode(data); [Benchmark] + public byte[] Decode2() => Hex.Decode2(data); + + //[Benchmark] public byte[] DecodeSubString() => DecodeSubString(data); } } diff --git a/benches/Jellyfin.Common.Benches/Program.cs b/benches/Jellyfin.Common.Benches/Program.cs index b218b0dc1..e7d51c1b5 100644 --- a/benches/Jellyfin.Common.Benches/Program.cs +++ b/benches/Jellyfin.Common.Benches/Program.cs @@ -7,7 +7,7 @@ namespace Jellyfin.Common.Benches { public static void Main(string[] args) { - _ = BenchmarkRunner.Run(); + //_ = BenchmarkRunner.Run(); _ = BenchmarkRunner.Run(); } }