aboutsummaryrefslogtreecommitdiff
path: root/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs
diff options
context:
space:
mode:
Diffstat (limited to 'benches/Jellyfin.Common.Benches/HexEncodeBenches.cs')
-rw-r--r--benches/Jellyfin.Common.Benches/HexEncodeBenches.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs b/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs
new file mode 100644
index 000000000..e7b446cc2
--- /dev/null
+++ b/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs
@@ -0,0 +1,29 @@
+using System;
+using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Running;
+using MediaBrowser.Common;
+
+namespace Jellyfin.Common.Benches
+{
+ [MemoryDiagnoser]
+ public class HexEncodeBenches
+ {
+ private const int N = 1000;
+ private readonly byte[] data;
+
+ public HexEncodeBenches()
+ {
+ data = new byte[N];
+ new Random(42).NextBytes(data);
+ }
+
+ [Benchmark]
+ public string HexEncode() => Hex.Encode(data);
+
+ [Benchmark]
+ public string BitConverterToString() => BitConverter.ToString(data);
+
+ [Benchmark]
+ public string BitConverterToStringWithReplace() => BitConverter.ToString(data).Replace("-", "");
+ }
+}