jellyfin/benches/Jellyfin.Common.Benches/HexEncodeBenches.cs

33 lines
791 B
C#
Raw Normal View History

2019-10-18 15:22:08 -07:00
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using MediaBrowser.Common;
namespace Jellyfin.Common.Benches
{
[MemoryDiagnoser]
public class HexEncodeBenches
{
2019-11-01 08:26:54 -07:00
private byte[] _data;
2019-10-18 15:22:08 -07:00
2019-11-01 08:26:54 -07:00
[Params(0, 10, 100, 1000, 10000, 1000000)]
public int N { get; set; }
[GlobalSetup]
public void GlobalSetup()
2019-10-18 15:22:08 -07:00
{
2019-11-01 08:26:54 -07:00
_data = new byte[N];
new Random(42).NextBytes(_data);
2019-10-18 15:22:08 -07:00
}
[Benchmark]
2019-11-01 08:26:54 -07:00
public string HexEncode() => Hex.Encode(_data);
2019-10-18 15:22:08 -07:00
[Benchmark]
2019-11-01 08:26:54 -07:00
public string BitConverterToString() => BitConverter.ToString(_data);
2019-10-18 15:22:08 -07:00
[Benchmark]
2019-11-01 08:26:54 -07:00
public string BitConverterToStringWithReplace() => BitConverter.ToString(_data).Replace("-", "");
2019-10-18 15:22:08 -07:00
}
}