-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds the Dopes performance test
- Loading branch information
1 parent
6f1fc26
commit ff61bc2
Showing
3 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/SamplesApp/UITests.Shared/Windows_UI_Xaml/Performance/Performance_Dopes.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<Page | ||
x:Class="UITests.Windows_UI_Xaml.Performance.Performance_Dopes" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Windows_UI_Xaml.Performance" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid Background="Black"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="55" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Canvas x:Name="absolute" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"> | ||
|
||
</Canvas> | ||
|
||
<Grid x:Name="grid" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
</Grid> | ||
|
||
<TextBlock x:Name="dopes" | ||
Grid.Row="0" | ||
Grid.Column="0" | ||
Margin="0,20,0,0" | ||
Padding="7,7,7,7" | ||
Foreground="White" | ||
VerticalAlignment="Top" | ||
HorizontalAlignment="Center" | ||
Text="Warming up.." | ||
Visibility="Collapsed"/> | ||
|
||
<StackPanel x:Name="buttons" | ||
Orientation="Horizontal" | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
VerticalAlignment="Bottom" | ||
HorizontalAlignment="Center" | ||
Margin="5,0,0,25" > | ||
|
||
<Button x:Name="stop" | ||
Content="@ Stop" | ||
Background="Red" | ||
HorizontalAlignment="Center" | ||
Visibility="Collapsed" | ||
Click="Stop_Clicked"/> | ||
|
||
<Button x:Name="startST" | ||
Content="@ Build" | ||
Background="Blue" | ||
Click="startST_Clicked"/> | ||
<Button x:Name="startGridST" | ||
Content="@ Grid" | ||
Background="Blue" | ||
Click="startGridST_Clicked"/> | ||
<Button x:Name="startChangeST" | ||
Content="@ Change" | ||
Background="Blue" | ||
Click="startChangeST_Clicked"/> | ||
<Button x:Name="startReuseST" | ||
Content="@ Reuse" | ||
Background="Blue" | ||
Click="startChangeReuse_Clicked"/> | ||
|
||
</StackPanel> | ||
|
||
</Grid> | ||
</Page> |
255 changes: 255 additions & 0 deletions
255
src/SamplesApp/UITests.Shared/Windows_UI_Xaml/Performance/Performance_Dopes.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Uno.UI.Samples.Controls; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace UITests.Windows_UI_Xaml.Performance | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
[SampleControlInfo("Performance", "MarkupExtension")] | ||
public sealed partial class Performance_Dopes : Page | ||
{ | ||
volatile bool breakTest = false; | ||
const int max = 600; | ||
|
||
public Performance_Dopes() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void StartTestST() | ||
{ | ||
var rand = new Random(0); | ||
|
||
breakTest = false; | ||
|
||
var width = absolute.ActualWidth; | ||
var height = absolute.ActualHeight; | ||
|
||
const int step = 20; | ||
var labels = new TextBlock[step * 2]; | ||
|
||
var processed = 0; | ||
|
||
long prevTicks = 0; | ||
long prevMs = 0; | ||
int prevProcessed = 0; | ||
double avgSum = 0; | ||
int avgN = 0; | ||
var sw = new Stopwatch(); | ||
|
||
Action loop = null; | ||
|
||
loop = () => | ||
{ | ||
var now = sw.ElapsedMilliseconds; | ||
if (breakTest) | ||
{ | ||
var avg = avgSum / avgN; | ||
dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21); | ||
return; | ||
} | ||
//60hz, 16ms to build the frame | ||
while (sw.ElapsedMilliseconds - now < 16) | ||
{ | ||
var label = new TextBlock() | ||
{ | ||
Text = "Dope", | ||
Foreground = new SolidColorBrush(Color.FromArgb(0xFF, (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255))) | ||
}; | ||
label.RenderTransform = new RotateTransform() { Angle = rand.NextDouble() * 360 }; | ||
Canvas.SetLeft(label, rand.NextDouble() * width); | ||
Canvas.SetTop(label, rand.NextDouble() * height); | ||
if (processed > max) | ||
{ | ||
absolute.Children.RemoveAt(0); | ||
} | ||
absolute.Children.Add(label); | ||
processed++; | ||
if (sw.ElapsedMilliseconds - prevMs > 500) | ||
{ | ||
var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency); | ||
prevTicks = sw.ElapsedTicks; | ||
prevProcessed = processed; | ||
if (processed > max) | ||
{ | ||
dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15); | ||
avgSum += r; | ||
avgN++; | ||
} | ||
prevMs = sw.ElapsedMilliseconds; | ||
} | ||
} | ||
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop()); | ||
}; | ||
|
||
sw.Start(); | ||
|
||
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => loop()); | ||
} | ||
|
||
private void StartTestReuseST() | ||
{ | ||
var rand = new Random(0); | ||
|
||
breakTest = false; | ||
|
||
var width = absolute.ActualWidth; | ||
var height = absolute.ActualHeight; | ||
|
||
const int step = 20; | ||
var labels = new TextBlock[step * 2]; | ||
|
||
var processed = 0; | ||
|
||
long prevTicks = 0; | ||
long prevMs = 0; | ||
int prevProcessed = 0; | ||
double avgSum = 0; | ||
int avgN = 0; | ||
var sw = new Stopwatch(); | ||
|
||
Action loop = null; | ||
|
||
System.Collections.Concurrent.ConcurrentBag<TextBlock> _cache = new System.Collections.Concurrent.ConcurrentBag<TextBlock>(); | ||
|
||
loop = () => | ||
{ | ||
var now = sw.ElapsedMilliseconds; | ||
if (breakTest) | ||
{ | ||
var avg = avgSum / avgN; | ||
dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21); | ||
return; | ||
} | ||
//60hz, 16ms to build the frame | ||
while (sw.ElapsedMilliseconds - now < 16) | ||
{ | ||
if (!_cache.TryTake(out var label)) | ||
{ | ||
label = new TextBlock(); | ||
} | ||
label.Text = "Dope"; | ||
label.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255))); | ||
label.RenderTransform = new RotateTransform() { Angle = rand.NextDouble() * 360 }; | ||
Canvas.SetLeft(label, rand.NextDouble() * width); | ||
Canvas.SetTop(label, rand.NextDouble() * height); | ||
if (processed > max) | ||
{ | ||
_cache.Add(absolute.Children[0] as TextBlock); | ||
absolute.Children.RemoveAt(0); | ||
} | ||
absolute.Children.Add(label); | ||
processed++; | ||
if (sw.ElapsedMilliseconds - prevMs > 500) | ||
{ | ||
var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency); | ||
prevTicks = sw.ElapsedTicks; | ||
prevProcessed = processed; | ||
if (processed > max) | ||
{ | ||
dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15); | ||
avgSum += r; | ||
avgN++; | ||
} | ||
prevMs = sw.ElapsedMilliseconds; | ||
} | ||
} | ||
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop()); | ||
}; | ||
|
||
sw.Start(); | ||
|
||
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop()); | ||
} | ||
|
||
private void SetControlsAtStart() | ||
{ | ||
startChangeST.Visibility = startST.Visibility = startGridST.Visibility = Visibility.Collapsed; | ||
stop.Visibility = dopes.Visibility = Visibility.Visible; | ||
absolute.Children.Clear(); | ||
grid.Children.Clear(); | ||
dopes.Text = "Warming up.."; | ||
} | ||
|
||
private void startMT_Clicked(System.Object sender, object e) | ||
{ | ||
SetControlsAtStart(); | ||
//StartTestMT2(); | ||
} | ||
|
||
private void startST_Clicked(System.Object sender, object e) | ||
{ | ||
SetControlsAtStart(); | ||
StartTestST(); | ||
} | ||
|
||
private void startGridST_Clicked(System.Object sender, object e) | ||
{ | ||
SetControlsAtStart(); | ||
//StartTestGridST(); | ||
} | ||
|
||
private void startChangeST_Clicked(System.Object sender, object e) | ||
{ | ||
SetControlsAtStart(); | ||
//StartTestChangeST(); | ||
} | ||
|
||
private void startChangeReuse_Clicked(System.Object sender, object e) | ||
{ | ||
SetControlsAtStart(); | ||
StartTestReuseST(); | ||
} | ||
|
||
private void Stop_Clicked(System.Object sender, object e) | ||
{ | ||
breakTest = true; | ||
stop.Visibility = Visibility.Collapsed; | ||
startChangeST.Visibility = startST.Visibility = startGridST.Visibility = Visibility.Visible; | ||
} | ||
|
||
} | ||
} |