소스 검색

Multiplication is faster than bit shifting

Bond_009 5 년 전
부모
커밋
593107e190
3개의 변경된 파일6개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      MediaBrowser.Common/Hex.cs
  2. 4 1
      benches/Jellyfin.Common.Benches/HexDecodeBenches.cs
  3. 1 1
      benches/Jellyfin.Common.Benches/Program.cs

+ 1 - 1
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;

+ 4 - 1
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);
     }
 }

+ 1 - 1
benches/Jellyfin.Common.Benches/Program.cs

@@ -7,7 +7,7 @@ namespace Jellyfin.Common.Benches
     {
         public static void Main(string[] args)
         {
-            _ = BenchmarkRunner.Run<HexEncodeBenches>();
+            //_ = BenchmarkRunner.Run<HexEncodeBenches>();
             _ = BenchmarkRunner.Run<HexDecodeBenches>();
         }
     }