In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the methods of ASP.NET page optimization for you, the content of the article is of high quality, so the editor will share it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Today I would like to share with you: a way to optimize the speed of page execution.
Using this method, you can use the execution speed of the page to achieve an improvement of [8 times].
In order to give you an intuitive understanding of the effect of optimization, I have prepared the following screenshots of the test results:
Test environment:
Windows Server 2003 SP2
Viaual Studio 2008, use your own WebDev.WebServer.EXE to run the website program.
(ThinkPad SL510): Core2 T6670 2.2GHz, 4G memory
The numbers in the two red boxes reflect the execution time before and after optimization.
The figures show that the execution time is more than 8 times different before and after optimization.
The test result of this article is only a reference number, and this result is only based on the test page I designed.
In the process of optimization, if you do not use server controls, then the pressure on GC can not be tested.
In the course of testing, I also found that the test results are not very stable, so the screenshot has a certain chance.
The test page may be one-sided in some ways, so the results are for reference only.
Test background
After looking at the optimization results, let's introduce: what exactly is this test testing?
Now there are a lot of ASP.NET developers who should start learning from ASP.NET 's WebForm programming model. Everyone likes to use server controls, no matter what output, will use server controls. Sometimes in order to render clean HTML code on the page, some people choose to use simple server controls such as Repeater,Literal. Some people may think that I no longer use a powerful and complex control like GridView, and the page execution speed is already fast.
Is that true?
The starting point of today's test starts with using a simple server, and I will do a series of performance optimizations for it in two stages.
In the end, there are three results in the above figure, which reflect the improvement process of secondary optimization.
Before continuing with the introduction, there is one point I would like to make clear:
The optimization process involves the use of ASP.NET server controls, and the test results are only a reference number.
If you think your development work is very dependent on the use of server controls
Then the test results are meaningless to you, please don't worry about the results.
Testing method
In this optimization process, I did not design a very complex test page, but a very simple test page, the effect of the page is as follows:
This page actually shows a bunch of hyperlinks from the recommended ranking list in the sidebar of my blog, with a total of 20 records. I asked the page to repeat the output five times, that is, 100 hyperlinks were generated.
The test data is obtained as follows:
I copied the HTML code from the recommended list in the sidebar of my blog and saved it to a file:
Then, when the site initializes, extract the link address and display text from this HTML code, and save it to a list of BlogInfo, as follows:
Public class BlogInfo {public string Title; public string Href;} public static class XmlDb {public static List Blogs {get; private set;} public static void LoadBlogs () {string filePath = Path.Combine (HttpRuntime.AppDomainAppPath, @ "App_Data\ RecommendList.html"); XElement html = XElement.Parse (System.IO.File.ReadAllText (filePath)) Blogs = (from an in html.Elements ("li") .Elements ("a") select new BlogInfo {Title = a.Value, Href = a.Attribute ("href") .Value}) .ToList ();}}
During the test, the contents of XmlDb.Blogs are displayed on the web page.
I think this test is relatively close to real-world development.
Here's another question: how do I test the execution speed of the page?
Although it is an easy way to create a HttpWebRequest access page, I do not intend to do so.
Because from the time the HttpWebRequest initiates the call to getting the result, there is not only the execution time of the page, but also a lot of extra call overhead. In the end, I chose the way in which I looped to call Server.Execute to execute the page and count the time in an HTTP request. In fact, how to choose the test method is fair to the two test subjects. It's just that minimizing some extra invocation overhead will make the test results more different and more obvious.
Description: to make the test code easy to write, I used the MyMVC framework.
Test case 1:WebFromPage.aspx
The test background and test method are introduced earlier. Now let's introduce the first test case, which is written in the most classic way in the WebForm programming model.
Page code:
PagePerformanceTest http://www.cnblogs.com/fish-li/
This is WebFromPage.aspx
CodeFile code of the page:
Public partial class TestPage_WebFromPage: System.Web.UI.Page {protected override void OnLoad (EventArgs e) {base.OnLoad (e); repeater1.DataSource = XmlDb.Blogs; repeater1.DataBind (); repeater2.DataSource = XmlDb.Blogs; repeater2.DataBind (); repeater3.DataSource = XmlDb.Blogs; repeater3.DataBind (); repeater4.DataSource = XmlDb.Blogs Repeater4.DataBind (); repeater5.DataSource = XmlDb.Blogs; repeater5.DataBind ();} protected void repeater1_ItemDataBound (object sender, RepeaterItemEventArgs e) {if (e.Item.ItemType = = ListItemType.Item) {BlogInfo blog = e.Item.DataItem as BlogInfo; HyperLink link1 = e.Item.FindControl ("link1") as HyperLink Link1.NavigateUrl = blog.Href; link1.Text = blog.Title;}
Test the code:
[Action] public object Test1 (string callTimes) {int count = 0; int.TryParse (callTimes, out count); if (count)
Test the code:
[Action] public object Test2 (string callTimes) {int count = 0; int.TryParse (callTimes, out count); if (count)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.