mirror of
https://github.com/jellyfin/jellyfin
synced 2024-07-21 18:04:30 +00:00
Fix benches
This commit is contained in:
parent
593107e190
commit
60cb256835
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("-", "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Jellyfin.Common.Benches
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
||||
_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
||||
_ = BenchmarkRunner.Run<HexDecodeBenches>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue