• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

asp.net优化(二)

发布: 2007-6-30 23:38 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网
    1. Do not rely on exceptions in your code: Exceptions are very expensive and should rarely occur in your code. You should never use exceptions as a way to control normal program flow. If it is possible to detect in code a condition that would cause an exception, you should do that instead of waiting to catch the exception before handling that condition. Common scenarios include checking for null, assigning to a string that will be parsed into a numeric value, or checking for specific values before applying math operations. For example:

    1. // Consider changing this:try {   result = 100 / num;}catch (Exception e) {  result = 0;}// To this:if (num != 0)   result = 100 / num;else  result = 0;
    @# Consider changing this:Try   result = 100 / numCatch (e As Exception)  result = 0End Try// To this:If Not (num = 0)   result = 100 / numElse  result = 0End If// Consider changing this:try {   result = 100 / num;}catch (e:Exception) {  result = 0;}// To this:if (num != 0)   result = 100 / num;else  result = 0;
    C# VB JScript

    1. Use early binding in Visual Basic or JScript code: One of the advantages of Visual Basic, VBScript, and JScript is their typeless nature. Variables can be created simply by using them and need no explicit type declaration. When assigning from one type to another, conversions are performed automatically, as well. This can be both an advantage and a disadvantage, since late binding is a very expensive convenience in terms of performance.
    2. The Visual Basic language now supports type-safe programming through the use of a special Option Strict compiler directive. For backward compatibility, ASP.NET does not enable Option Strict by default. However, for optimal perfomance, you should enable Option Strict for your pages by using a Strict attribute on the page or Control directive:
    3. <%@ Page Language="VB" Strict="true" %><%Dim BDim C As String@# This causes a compiler error:A = "Hello"@# This causes a compiler error:B = "World"@# This does not:C = "!!!!!!"@# But this does:C = 0%>
    4. JScript also supports typeless programming, though it offers no compiler directive to force early binding. A variable is late-bound if:
    5. It is declared explicitly as an object.
    • It is a field of a class with no type declaration.
    • It is a private function/method member with no explicit type declaration and the type cannot be inferred from its use.
    1. The last distinction is complicated. The JScript compiler optimizes if it can figure out the type, based on how a variable is used. In the following example, the variable A is early-bound but the variable B is late-bound:
    2. var A;var B;A = "Hello";B = "World";B = 0;
    3. For the best performance, declare your JScript variables as having a type. For example, "var A : String".
    4. Port call-intensive COM components to managed code: The .NET Framework provides a remarkably easy way to interoperate with traditional COM components. The benefit is that you can take advantage of the new platform while preserving your existing code. However, there are some circumstances in which the performance cost of keeping your old components is greater than the cost to migrate your components to managed code. Every situation is unique, and the best way to decide what needs to be changed is to measure site performance. In general, however, the performance impact of COM interoperability is proportional to the number of function calls made or the amount of data marshaled from unmanaged to managed code. A component that requires a high volume of calls to interact with it is called "chatty," due to the number of communications between layers. You should consider porting such components to fully managed code to benefit from the performance gains provided by the .NET platform. Alternatively, you might consider redesigning your component to require fewer calls or to marshal more data at once.
    5. Use SQL stored procedures for data access: Of all the data access methods provided by the .NET Framework, SQL-based data access is the best choice for building scalable web applications with the best performance. When using the managed SQL provider, you can get an additional performance boost by using compiled stored procedures instead of ad hoc queries. For an example of using SQL stored procedures, refer to the section of this tutorial.
    6. Use SqlDataReader for a fast-forward, read-only data cursor: A SqlDataReader object provides a forward, read-only cursor over data retrieved from a SQL database. Because SqlDataReader uses Tabular Data Stream (TDS) packets to read data directly from a database connection, it provides better performance than using a DataSet, if you can use that for your scenario. Because SqlDataReader supports the IEnumerable interface, you can even bind server controls, as well. For an example of using SqlDataReader, see the section of this tutorial.
    7. Cache data and output wherever possible: The ASP.NET programming model provides a simple mechanism for caching page output or data when it does not need to be dynamically computed for every request. You can design your pages with caching in mind to optimize those places in your application that you expect to have the most traffic. More than any feature of the .NET Framework, the appropriate use of caching can enhance the performance of your site, sometimes by an order of magnitude or more. For more information about how to use caching, see the section of this tutorial.
    8. Enable Web gardening for multiprocessor computers: The ASP.NET process model helps enable scalability on multiprocessor machines by distributing the work to several processes, one for each CPU, each with processor affinity set to its CPU. The technique is called Web gardening, and can dramatically improve the performance of some applications. To learn how to enable Web gardening, refer to the section.
    9. Do not forget to disable Debug mode: The <compilation> section in ASP.NET configuration controls whether an application is compiled in Debug mode, or not. Debug mode degrades performance significantly. Always remember to disable Debug mode before you deploy a production application or measure performance. For more information about Debug mode, refer to the section entitled .

    延伸阅读

    文章来源于领测软件测试网 https://www.ltesting.net/


    关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
    版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
    北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
    技术支持和业务联系:info@testage.com.cn 电话:010-51297073

    软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网