using System.Text;
using BenchmarkDotNet.Attributes;
using Tui = Terminal.Gui;
namespace Terminal.Gui.Benchmarks.Text.RuneExtensions;
///
/// Benchmarks for performance fine-tuning.
///
[MemoryDiagnoser]
[BenchmarkCategory (nameof (Tui.RuneExtensions))]
public class IsSurrogatePair
{
///
/// Benchmark for previous implementation.
///
///
[Benchmark]
[ArgumentsSource (nameof (DataSource))]
public bool Previous (Rune rune)
{
return WithToString (rune);
}
///
/// Benchmark for current implementation.
///
/// Avoids intermediate heap allocations by using stack allocated buffer.
///
[Benchmark (Baseline = true)]
[ArgumentsSource (nameof (DataSource))]
public bool Current (Rune rune)
{
return Tui.RuneExtensions.IsSurrogatePair (rune);
}
///
/// Previous implementation with intermediate string allocation.
///
private static bool WithToString (Rune rune)
{
return char.IsSurrogatePair (rune.ToString (), 0);
}
public static IEnumerable