Wednesday, January 14, 2015

ASP.NET Performance Test Much Faster Than Webforms

ASP.NET Performance Test Much Faster Than Webforms

from
http://www.codeproject.com/Articles/864950/ASP-NET-MVC-vs-ASP-NET-WebForm-performance-compari

ASP.NET MVC vs ASP.NET WebForm performance comparison

13 Jan 2015 CPOL
The intention of this article is to compare performance between ASP.NET WebForms and ASP.NET MVC. One the main reasons of moving from Webforms to MVC is performance, performance and performance.

Contents

Intention of this test
Code for the test
Out of scope
How was the test conducted?
Performance criteria
Conclusion of test
ASP.NET MVC as solution
Reading 1
Web Forms
MVC
Reading 2
Webform
MVC
Reading 3
WebForm
MVC
Reading 4
WebForm
MVC
Reading 5
Webform
MVC
Reading 6
Webform
MVC
Further reading

Intention of this test

The intention of this article is to compare performance between ASP.NET WebForms and ASP.NET MVC.One the main reasons of moving from Webforms to MVC is performance, performance and performance.
FYI :-In case you are new to MVC you can start from the video given at the end of the article.

Code for the test

For this test we created two projects one in ASP.NET MVC and the other in ASP.NET Webforms.We have kept the test absolutely simple.Both the projects display 20 textboxes and there is a grid loaded with 1000 records.
Below is the ASP.NET Webform code behind which binds with a grid server control.
        protected void Page_Load(object sender, EventArgs e)
        {
for(int i=0;i<1000;i++)
            {
obj.Add(DateTime.Now.ToString());
            }
            GridView1.DataSource = obj;
GridView1.DataBind();
        }
    }
On the ASPX UI we have 20 textboxes which uses the server controls of ASP.NET Webforms.
<asp:TextBox ID="TextBox1" runat="server" BackColor="#FF66FF"></asp:TextBox>

<asp:TextBox ID="TextBox2" runat="server" BackColor="#FF66FF"></asp:TextBox>

<asp:TextBox ID="TextBox3" runat="server" BackColor="#FF66FF"></asp:TextBox>

…….
<asp:TextBox ID="TextBox6" runat="server" BackColor="#FF66FF"></asp:TextBox>

In ASP.NET MVC project also we have similar kind of logic. We have 20 textboxes created using HTML control and simple loop which creates HTML table.
<input id="Text1" type="text" style="background-color:#FF66FF" />

<input id="Text1" type="text" style="background-color:#FF66FF" />

<input id="Text1" type="text" style="background-color:#FF66FF" />

@{
List<string> obj = new List<string>();
for (int i = 0; i < 1000; i++)
{
obj.Add(DateTime.Now.ToString());
}
}
<table>
<tr><td>Item</td></tr>
@{
foreach (string str in obj) 
      {
<tr><td>@str</td></tr>
      }
}
</table>

Out of scope

In this test we have not used JSON, Jquery , Ajax because we wanted to test performance of these platforms only and not when they get clubbed with other technical things like HTML 5 , Ajax etc.

How was the test conducted?

Test was conducted with the below specifications using VSTS and telerik load test software:-
  • User load 25 users.
  • Run duration of test was 10 minutes.
  • Machine config DELL 8 GB Ram, Core i3
  • Project was hosted in IIS 8.
  • Project was created using MVC 5.
  • Network LAN connection was assumed. So this test does not account for network lag for now.
  • Browser in the test selected Chrome and Internet explorer.
  • Multiple reading where taken during the test to average unknown events. 7 readings where taken and all readings are published in this article as reading 1 , 2 and so on.

Performance criteria

Performance was measured using two criteria’s Average page response time and Response content in bytes.
Average Page response time :- This value is the average time the 25 users get the page output when the load testing is executed.
Response content length :-Number of average total bytes transferred for every request. This criteria is taken because we suspect the server controls generate more amount of HTML as compared to when we write custom HTML.

Conclusion of test

Response time
Response time of MVC was much better as compared to Webform. We found ASP.NET MVC response time was two times better than Webforms.
The reason is but obvious when a request is sent to Webforms there is a complex ASP.NET page life cycle which gets executed in the code behind. This code behind is nothing but sort of conversion logic which converts the ASP.NET server controls to HTML.
In ASP.NET MVC there is no code behind and no such conversion is required as the controls are in HTML format themself.
Content length
For the same kind of logic the HTML content length generatedfrom Webform was twice than MVC.
When we viewed the view source we saw huge view state data generated by Webform which was not present in MVC. This means more bandwidth will be consumed when we surf ASP.NET Webform sites as compared to ASP.NET MVC sites.

ASP.NET MVC as solution

If you see the conclusion from the load test we need a solution which does not have code behind and server controls. So when you create ASP.NET MVC projects you will not find NOcode behind and server controls.
Below is a snapshot of MVC views and you can see there is .CSHTML but there is no CSHTML.CS.
If you go a MVC view and click on toolbox it only HTML tab and all the server controls have gone of completely.
You can also read this in depth article which talk about what we have missed in ASP.NET MVC from Webforms.
Below are all the seven readings pasted for both Webform and MVC. These readings would provide you more insight on the performance factor between these technologies.

Reading 1

Web Forms


No comments:

Post a Comment