blob: 7abf93c510d73ce5faeed6a46573a36db5bf998a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using MediaBrowser.Common;
namespace Jellyfin.Common.Benches
{
[MemoryDiagnoser]
public class HexEncodeBenches
{
private byte[] _data;
[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);
}
[Benchmark]
public string HexEncode() => Hex.Encode(_data);
[Benchmark]
public string BitConverterToString() => BitConverter.ToString(_data);
[Benchmark]
public string BitConverterToStringWithReplace() => BitConverter.ToString(_data).Replace("-", "");
}
}
|