The Free Software Media System - Server Backend & API
Fix benches
Bond_00960cb256835ff
diff --git a/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs b/benches/Jellyfin.Common.Benches/HexDecodeBenches.csindex 5cd47202c9..d9a107b696 100644--- a/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs+++ b/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs@@ -9,20 +9,26 @@ namespace Jellyfin.Common.Benches[MemoryDiagnoser]public class HexDecodeBenches{- [Params(/*0,*/ 10, 100, 1000, 10000, 1000000)]- public int N { get; set; }+ private string _data;- private string data;+ [Params(0, 10, 100, 1000, 10000, 1000000)]+ public int N { get; set; }[GlobalSetup]public void GlobalSetup(){- var tmp = new byte[N];- new Random(42).NextBytes(tmp);- data = Hex.Encode(tmp);+ var bytes = new byte[N];+ new Random(42).NextBytes(bytes);+ _data = Hex.Encode(bytes);}- public static byte[] DecodeSubString(string str)+ [Benchmark]+ public byte[] Decode() => Hex.Decode(_data);++ [Benchmark]+ public byte[] DecodeSubString() => DecodeSubString(_data);++ private static byte[] DecodeSubString(string str){byte[] bytes = new byte[str.Length / 2];for (int i = 0; i < str.Length; i += 2)@@ -35,14 +41,5 @@ namespace Jellyfin.Common.Benchesreturn bytes;}-- [Benchmark]- 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/HexEncodeBenches.cs b/benches/Jellyfin.Common.Benches/HexEncodeBenches.csindex e7b446cc20..7abf93c510 100644--- a/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs+++ b/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs@@ -8,22 +8,25 @@ namespace Jellyfin.Common.Benches[MemoryDiagnoser]public class HexEncodeBenches{- private const int N = 1000;- private readonly byte[] data;+ private byte[] _data;- public HexEncodeBenches()+ [Params(0, 10, 100, 1000, 10000, 1000000)]+ public int N { get; set; }++ [GlobalSetup]+ public void GlobalSetup(){- data = new byte[N];- new Random(42).NextBytes(data);+ _data = new byte[N];+ new Random(42).NextBytes(_data);}[Benchmark]- public string HexEncode() => Hex.Encode(data);+ public string HexEncode() => Hex.Encode(_data);[Benchmark]- public string BitConverterToString() => BitConverter.ToString(data);+ public string BitConverterToString() => BitConverter.ToString(_data);[Benchmark]- public string BitConverterToStringWithReplace() => BitConverter.ToString(data).Replace("-", "");+ public string BitConverterToStringWithReplace() => BitConverter.ToString(_data).Replace("-", "");}}diff --git a/benches/Jellyfin.Common.Benches/Program.cs b/benches/Jellyfin.Common.Benches/Program.csindex e7d51c1b54..b218b0dc10 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<HexEncodeBenches>();+ _ = BenchmarkRunner.Run<HexEncodeBenches>();_ = BenchmarkRunner.Run<HexDecodeBenches>();}}