mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Fix benches
This commit is contained in:
parent
593107e190
commit
60cb256835
@ -9,20 +9,26 @@ namespace Jellyfin.Common.Benches
|
|||||||
[MemoryDiagnoser]
|
[MemoryDiagnoser]
|
||||||
public class HexDecodeBenches
|
public class HexDecodeBenches
|
||||||
{
|
{
|
||||||
[Params(/*0,*/ 10, 100, 1000, 10000, 1000000)]
|
private string _data;
|
||||||
public int N { get; set; }
|
|
||||||
|
|
||||||
private string data;
|
[Params(0, 10, 100, 1000, 10000, 1000000)]
|
||||||
|
public int N { get; set; }
|
||||||
|
|
||||||
[GlobalSetup]
|
[GlobalSetup]
|
||||||
public void GlobalSetup()
|
public void GlobalSetup()
|
||||||
{
|
{
|
||||||
var tmp = new byte[N];
|
var bytes = new byte[N];
|
||||||
new Random(42).NextBytes(tmp);
|
new Random(42).NextBytes(bytes);
|
||||||
data = Hex.Encode(tmp);
|
_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];
|
byte[] bytes = new byte[str.Length / 2];
|
||||||
for (int i = 0; i < str.Length; i += 2)
|
for (int i = 0; i < str.Length; i += 2)
|
||||||
@ -35,14 +41,5 @@ namespace Jellyfin.Common.Benches
|
|||||||
|
|
||||||
return bytes;
|
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]
|
[MemoryDiagnoser]
|
||||||
public class HexEncodeBenches
|
public class HexEncodeBenches
|
||||||
{
|
{
|
||||||
private const int N = 1000;
|
private byte[] _data;
|
||||||
private readonly byte[] data;
|
|
||||||
|
|
||||||
public HexEncodeBenches()
|
[Params(0, 10, 100, 1000, 10000, 1000000)]
|
||||||
|
public int N { get; set; }
|
||||||
|
|
||||||
|
[GlobalSetup]
|
||||||
|
public void GlobalSetup()
|
||||||
{
|
{
|
||||||
data = new byte[N];
|
_data = new byte[N];
|
||||||
new Random(42).NextBytes(data);
|
new Random(42).NextBytes(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
public string HexEncode() => Hex.Encode(data);
|
public string HexEncode() => Hex.Encode(_data);
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
public string BitConverterToString() => BitConverter.ToString(data);
|
public string BitConverterToString() => BitConverter.ToString(_data);
|
||||||
|
|
||||||
[Benchmark]
|
[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)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
||||||
_ = BenchmarkRunner.Run<HexDecodeBenches>();
|
_ = BenchmarkRunner.Run<HexDecodeBenches>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user