Skip to content

Commit

Permalink
Add batch generate
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Apr 12, 2024
1 parent dbb147d commit 7e64c05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<Label x:Name="info" Text="Click a button" VerticalOptions="Center"/>
<Button Text="Clear Grid" Clicked="ClearGrid_Clicked"/>
<Button Text="Generate Grid" Clicked="Button_Clicked"/>
<Entry x:Name="BatchSize" Text="15"/>
<Button Text="Batch Generate Grid" Clicked="BatchGenerate_Clicked"/>

<HorizontalStackLayout x:Name="myGridWrapper">
<Grid x:Name="contentGrid"/>
Expand Down
31 changes: 28 additions & 3 deletions src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Maui.Controls.Sample;

public partial class MainPage : ContentPage
{
const int rowCount = 30;
const int columnCount = 30;

public MainPage()
{
InitializeComponent();
Expand All @@ -24,9 +27,6 @@ private void ClearGrid_Clicked(object sender, EventArgs e)

private void Button_Clicked(object sender, EventArgs e)
{
const int rowCount = 30;
const int columnCount = 30;

Stopwatch sw = Stopwatch.StartNew();
contentGrid.Clear();

Expand All @@ -42,4 +42,29 @@ private void Button_Clicked(object sender, EventArgs e)
sw.Stop();
info.Text = $"Clearing grid took: {sw.ElapsedMilliseconds} ms";
}

private void BatchGenerate_Clicked(object sender, EventArgs e)
{
Stopwatch sw = Stopwatch.StartNew();

int batchSize = int.Parse(BatchSize.Text);

for (int i = 0; i < batchSize; i++)
{
contentGrid.Clear();

for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
{
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
{
Label label = new Label() { Text = $"[{columnIndex}x{rowIndex}]" };
contentGrid.Add(label, column: columnIndex, row: rowIndex);
}
}
}

sw.Stop();
info.Text = $"Grid was created {batchSize} times and it took {sw.ElapsedMilliseconds} ms in total. Avg run took {Math.Round(sw.ElapsedMilliseconds / (double)batchSize, 2)} ms";
}

}

0 comments on commit 7e64c05

Please sign in to comment.