summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs
blob: bdf291e78fc24418712c81d15ddd6dc4791a8f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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);
			}
		}
	}
}