2
0

HexEncodeBenches.cs 791 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using BenchmarkDotNet.Attributes;
  3. using BenchmarkDotNet.Running;
  4. using MediaBrowser.Common;
  5. namespace Jellyfin.Common.Benches
  6. {
  7. [MemoryDiagnoser]
  8. public class HexEncodeBenches
  9. {
  10. private byte[] _data;
  11. [Params(0, 10, 100, 1000, 10000, 1000000)]
  12. public int N { get; set; }
  13. [GlobalSetup]
  14. public void GlobalSetup()
  15. {
  16. _data = new byte[N];
  17. new Random(42).NextBytes(_data);
  18. }
  19. [Benchmark]
  20. public string HexEncode() => Hex.Encode(_data);
  21. [Benchmark]
  22. public string BitConverterToString() => BitConverter.ToString(_data);
  23. [Benchmark]
  24. public string BitConverterToStringWithReplace() => BitConverter.ToString(_data).Replace("-", "");
  25. }
  26. }