4 changed files with 185 additions and 0 deletions
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.UnitTests; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
|
||||
|
namespace Avalonia.Benchmarks.Layout |
||||
|
{ |
||||
|
[MemoryDiagnoser, InProcess, IterationCount(16)] |
||||
|
public class CalendarBenchmark : IDisposable |
||||
|
{ |
||||
|
private readonly IDisposable _app; |
||||
|
private readonly TestRoot _root; |
||||
|
|
||||
|
public CalendarBenchmark() |
||||
|
{ |
||||
|
_app = UnitTestApplication.Start(TestServices.StyledWindow.With(renderInterface: new NullRenderingPlatform(), threadingInterface: new NullThreadingPlatform())); |
||||
|
|
||||
|
_root = new TestRoot(true, null) |
||||
|
{ |
||||
|
Renderer = new NullRenderer(), |
||||
|
}; |
||||
|
|
||||
|
_root.LayoutManager.ExecuteInitialLayoutPass(_root); |
||||
|
} |
||||
|
|
||||
|
[Benchmark] |
||||
|
[MethodImpl(MethodImplOptions.NoInlining)] |
||||
|
public void CreateCalendar() |
||||
|
{ |
||||
|
var calendar = new Calendar(); |
||||
|
|
||||
|
_root.Child = calendar; |
||||
|
|
||||
|
_root.LayoutManager.ExecuteLayoutPass(); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_app.Dispose(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Platform; |
||||
|
|
||||
|
namespace Avalonia.Benchmarks |
||||
|
{ |
||||
|
internal class NullFormattedTextImpl : IFormattedTextImpl |
||||
|
{ |
||||
|
public Size Constraint { get; } |
||||
|
|
||||
|
public Rect Bounds { get; } |
||||
|
|
||||
|
public string Text { get; } |
||||
|
|
||||
|
public IEnumerable<FormattedTextLine> GetLines() |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public TextHitTestResult HitTestPoint(Point point) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public Rect HitTestTextPosition(int index) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IEnumerable<Rect> HitTestTextRange(int index, int length) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.UnitTests; |
||||
|
|
||||
|
namespace Avalonia.Benchmarks |
||||
|
{ |
||||
|
internal class NullRenderingPlatform : IPlatformRenderInterface |
||||
|
{ |
||||
|
public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, double fontSize, TextAlignment textAlignment, |
||||
|
TextWrapping wrapping, Size constraint, IReadOnlyList<FormattedTextStyleSpan> spans) |
||||
|
{ |
||||
|
return new NullFormattedTextImpl(); |
||||
|
} |
||||
|
|
||||
|
public IGeometryImpl CreateEllipseGeometry(Rect rect) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IGeometryImpl CreateLineGeometry(Point p1, Point p2) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IGeometryImpl CreateRectangleGeometry(Rect rect) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IStreamGeometryImpl CreateStreamGeometry() |
||||
|
{ |
||||
|
return new MockStreamGeometryImpl(); |
||||
|
} |
||||
|
|
||||
|
public IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IBitmapImpl LoadBitmap(string fileName) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IBitmapImpl LoadBitmap(Stream stream) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public IFontManagerImpl CreateFontManager() |
||||
|
{ |
||||
|
return new MockFontManagerImpl(); |
||||
|
} |
||||
|
|
||||
|
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Reactive.Disposables; |
||||
|
using System.Threading; |
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Threading; |
||||
|
|
||||
|
namespace Avalonia.Benchmarks |
||||
|
{ |
||||
|
internal class NullThreadingPlatform : IPlatformThreadingInterface |
||||
|
{ |
||||
|
public void RunLoop(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) |
||||
|
{ |
||||
|
return Disposable.Empty; |
||||
|
} |
||||
|
|
||||
|
public void Signal(DispatcherPriority priority) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public bool CurrentThreadIsLoopThread => true; |
||||
|
|
||||
|
public event Action<DispatcherPriority?> Signaled; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue