diff options
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs')
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs new file mode 100644 index 00000000..bdf291e7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +using NUnit.Framework; +using System.Diagnostics; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class SimpleContentPageCode : ContentPage + { + public SimpleContentPageCode () + { + Content = new Label { + Text="Hello, Xamarin.Forms!", + VerticalOptions=LayoutOptions.CenterAndExpand, + HorizontalOptions=LayoutOptions.CenterAndExpand + }; + } + + public SimpleContentPageCode (bool useCompiledXaml) : this () + { + } + } + public partial class SimpleContentPage : ContentPage + { + public SimpleContentPage () + { + InitializeComponent (); + } + + public SimpleContentPage (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [Test] + [Ignore] + public void XamlCIs20TimesFasterThanXaml () + { + var swXamlC = new Stopwatch (); + var swXaml = new Stopwatch (); + + swXamlC.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (true); + swXamlC.Stop (); + + swXaml.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (false); + swXaml.Stop (); + + Assert.Less (swXamlC.ElapsedMilliseconds * 20, swXaml.ElapsedMilliseconds); + } + + [Test] + [Ignore] + public void XamlCIsNotMuchSlowerThanCode () + { + var swXamlC = new Stopwatch (); + var swCode = new Stopwatch (); + + swXamlC.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (true); + swXamlC.Stop (); + + swCode.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPageCode (false); + swCode.Stop (); + + Assert.LessOrEqual (swXamlC.ElapsedMilliseconds*.2, swCode.ElapsedMilliseconds); + } + } + } +}
\ No newline at end of file |