mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 16:58:01 +01:00
* touching publish.yml * Moved Examples into ./Examples * Moved Benchmarks into ./Tests * Moved Benchmarks into ./Tests * Moved UICatalog into ./Examples * Moved UICatalog into ./Examples 2 * Moved tests into ./Tests * Updated nuget
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System.Text;
|
||
using BenchmarkDotNet.Attributes;
|
||
using Tui = Terminal.Gui;
|
||
|
||
namespace Terminal.Gui.Benchmarks.Text.RuneExtensions;
|
||
|
||
/// <summary>
|
||
/// Benchmarks for <see cref="Tui.RuneExtensions.IsSurrogatePair"/> performance fine-tuning.
|
||
/// </summary>
|
||
[MemoryDiagnoser]
|
||
[BenchmarkCategory (nameof (Tui.RuneExtensions))]
|
||
public class IsSurrogatePair
|
||
{
|
||
/// <summary>
|
||
/// Benchmark for previous implementation.
|
||
/// </summary>
|
||
/// <param name="rune"></param>
|
||
[Benchmark]
|
||
[ArgumentsSource (nameof (DataSource))]
|
||
public bool Previous (Rune rune)
|
||
{
|
||
return WithToString (rune);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Benchmark for current implementation.
|
||
///
|
||
/// Avoids intermediate heap allocations by using stack allocated buffer.
|
||
/// </summary>
|
||
[Benchmark (Baseline = true)]
|
||
[ArgumentsSource (nameof (DataSource))]
|
||
public bool Current (Rune rune)
|
||
{
|
||
return Tui.RuneExtensions.IsSurrogatePair (rune);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Previous implementation with intermediate string allocation.
|
||
/// </summary>
|
||
private static bool WithToString (Rune rune)
|
||
{
|
||
return char.IsSurrogatePair (rune.ToString (), 0);
|
||
}
|
||
|
||
public static IEnumerable<object> DataSource ()
|
||
{
|
||
yield return new Rune ('a');
|
||
yield return "𝔹".EnumerateRunes ().Single ();
|
||
}
|
||
}
|