using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyWebApplication.Algoritmy
{
	public partial class StringBuilderPage : System.Web.UI.Page
	{
		private const int SIZE = 100000;

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			string result;

			// běžné skládání stringů
			result = string.Empty;
			Stopwatch sw1 = new Stopwatch();
			sw1.Start();
			for (int i = 0; i < SIZE; i++)
			{
				result = result + (char)(i % 26 + 65);
			}
			sw1.Stop();
			StringLb.Text = String.Format("{0:n0} ticks", sw1.ElapsedTicks);

			// StringBuilder
			result = string.Empty;
			var sw2 = new System.Diagnostics.Stopwatch();
			sw2.Start();
			var sb = new StringBuilder();
			for (int i = 0; i < SIZE; i++)
			{
				sb.Append((char)(i % 26 + 65));
			}
			result = sb.ToString();
			sw2.Stop();
			StringBuilderLb.Text = String.Format("{0:n0} ticks", sw2.ElapsedTicks);
		}
	}
}