aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benches/Jellyfin.Common.Benches/HexDecodeBenches.cs29
-rw-r--r--benches/Jellyfin.Common.Benches/HexEncodeBenches.cs19
-rw-r--r--benches/Jellyfin.Common.Benches/Program.cs2
3 files changed, 25 insertions, 25 deletions
diff --git a/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs b/benches/Jellyfin.Common.Benches/HexDecodeBenches.cs
index 5cd47202c..d9a107b69 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.Benches
return 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.cs
index e7b446cc2..7abf93c51 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.cs
index e7d51c1b5..b218b0dc1 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>();
}
}