ModernUO/Projects/Benchmarks/Benchmarks/Text/BenchmarkTextEncoding.cs
Kamron Batman 211c2ba8ee
fix(core): Streamlines text encoding (#407)
- [X] Streamlines text encoding
2021-01-13 18:56:32 -08:00

32 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Server.Text;
namespace Benchmarks.BenchmarkText
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
public class BenchmarkTextEncoding
{
private const string text =
"This is supposed to be a really long text Ƞă¼ÖƄŭȘú😅¥♓ǵDƤĂ😋ġǁ⚕😐'ƿī😪_l" +
"This is supposed to be a really long text Ƞă¼ÖƄŭȘú😅¥♓ǵDƤĂ😋ġǁ⚕😐'ƿī😪_l" +
"This is supposed to be a really long text Ƞă¼ÖƄŭȘú😅¥♓ǵDƤĂ😋ġǁ⚕😐'ƿī😪_l" +
"This is supposed to be a really long text Ƞă¼ÖƄŭȘú😅¥♓ǵDƤĂ😋ġǁ⚕😐'ƿī😪_l" +
"This is supposed to be a really long text Ƞă¼ÖƄŭȘú😅¥♓ǵDƤĂ😋ġǁ⚕😐'ƿī😪_l";
[Benchmark]
public byte[] TestEncodingOldReturnBytes()
{
var bytes = TextEncoding.UTF8.GetBytes(text);
return bytes;
}
[Benchmark]
public byte[] TestEncodingNewReturnBytes()
{
var bytes = text.GetBytesUtf8();
return bytes;
}
}
}