<%@ Page %>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
DateTime startTime, endTime;
string output = "";
TimeSpan span;
startTime=DateTime.Now;
for (int i=1;i<10000;i++)
{
output += i.ToString() + " ";
}
endTime=DateTime.Now;
span=new TimeSpan(endTime.Ticks-startTime.Ticks);
Response.Write("<hr>Time Using Concatenation: " + span.TotalSeconds.ToString() + "<hr>");
startTime=DateTime.Now;
System.Text.StringBuilder sb = new System.Text.StringBuilder(10000);
for (int i=1;i<10000;i++)
{
sb.Append(i.ToString());
sb.Append(" ");
}
endTime=DateTime.Now;
span=new TimeSpan(endTime.Ticks-startTime.Ticks);
Response.Write("<hr>Time Using StringBuilder: " + span.TotalSeconds.ToString() + "<hr>");
}
</script>
|