@ -3,6 +3,7 @@ using System.Linq;
using Avalonia.Controls ;
using Avalonia.Media ;
using Avalonia.Media.TextFormatting ;
using Avalonia.Skia ;
using Avalonia.UnitTests ;
using BenchmarkDotNet.Attributes ;
@ -13,24 +14,35 @@ namespace Avalonia.Benchmarks.Text;
[MaxWarmupCount(15)]
public class HugeTextLayout : IDisposable
{
private static readonly Random s_rand = new ( ) ;
private static readonly bool s_useSkia = true ;
private readonly IDisposable _ app ;
private string [ ] _ manySmallStrings ;
private static Random _ rand = new Random ( ) ;
private readonly string [ ] _ manySmallStrings ;
private static string RandomString ( int length )
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&?%$@" ;
return new string ( Enumerable . Repeat ( chars , length ) . Select ( s = > s [ _ rand . Next ( s . Length ) ] ) . ToArray ( ) ) ;
return new string ( Enumerable . Repeat ( chars , length ) . Select ( s = > s [ s_ rand. Next ( s . Length ) ] ) . ToArray ( ) ) ;
}
public HugeTextLayout ( )
{
_ manySmallStrings = Enumerable . Range ( 0 , 1 0 0 0 ) . Select ( x = > RandomString ( _ rand . Next ( 2 , 1 5 ) ) ) . ToArray ( ) ;
_ app = UnitTestApplication . Start (
TestServices . StyledWindow . With (
renderInterface : new NullRenderingPlatform ( ) ,
threadingInterface : new NullThreadingPlatform ( ) ,
standardCursorFactory : new NullCursorFactory ( ) ) ) ;
_ manySmallStrings = Enumerable . Range ( 0 , 1 0 0 0 ) . Select ( _ = > RandomString ( s_rand . Next ( 2 , 1 5 ) ) ) . ToArray ( ) ;
var testServices = TestServices . StyledWindow . With (
renderInterface : new NullRenderingPlatform ( ) ,
threadingInterface : new NullThreadingPlatform ( ) ,
standardCursorFactory : new NullCursorFactory ( ) ) ;
if ( s_useSkia )
{
testServices = testServices . With (
textShaperImpl : new TextShaperImpl ( ) ,
fontManagerImpl : new FontManagerImpl ( ) ) ;
}
_ app = UnitTestApplication . Start ( testServices ) ;
}
private const string Text = @ "Though, the objectives of the development of the prominent landmarks can be neglected in most cases, it should be realized that after the completion of the strategic decision gives rise to The Expertise of Regular Program (Carlton Cartwright in The Book of the Key Factor)