Http://drupal.org/node/201916
Http://drupal.org/node/206792
Http://www.newhua.com/2012/1205/187066_4.shtml
Original http://www.2cto.com/kf/201204/126311.html
Http://www.cnblogs.com/Miser/archive/2012/04/04/2432505.html
I have recently read high-performance JavaScript at http://book.douban.com/subject/5362856/, and compiled a series Article Consolidate the knowledge points. Although the tools are introduced at the end of the book, in order to have a more intuitive understanding in the subsequent articles, I plan to introduce the tools first. Code We can see that the performance analysis data is more understandable.
Yui profiler official address http://developer.yahoo.com/yui/profiler/
Introduction
Yui is a very good tool. It provides methods (profiling functions), profiling constructors, object (profiling objects) analysis and other auxiliary help.
If you want to analyze and appeal to something, you need to register the stuff in Yui profiler first, such as Yahoo. tool. profiler. registerfunction // Analysis Method
Yahoo. tool. profiler. registerconstructor // analysis Constructor
Yahoo. tool. profiler. registerobject // analysis object
You can use
Getaverage -- get the average execution time
Getcallcount -- number of calls
Getmax (name) -- maximum execution time
Getmin (name) -- Minimum execution time
Getfunctionreport (name) -- Report on appeal methods
How to use it?
The performance consumption of JavaScript String concatenation in different browsers is different. Let's take a look at its different performance in chrome 18 and ie10.
Function uidraw (){
}
Uidraw. Prototype. Draw = function (){
For (VAR I = 1000; I> = 0; I --){
VaR test_box = Document. getelementbyid ("test_box ");
Test_box.innerhtml + = '<span>' + I + '</span> ';
};
}
The test object is very simple. It is to find the HTML object with the ID of test_box, concatenate the string for 1000 times in a loop, and add it to the object.
Yui test code:
// Two objects to be tested
VaR ui1 = new uidraw ();
VaR ui2 = new uidraw ();
// Register the uidraw object to Yui profiler
Yahoo. tool. profiler. registerconstructor ("uidraw", window );
// Execute the methods of two objects respectively
Ui1.draw ();
Ui2.draw ();
// Get feedback report and Output
VaR report = Yahoo. tool. profiler. getfunctionreport ("uidraw. Prototype. Draw ");
Console. Log (report)
The performance of ie10 is worse than I expected:
AVG indicates the average execution time, cballs indicates the number of calls, Max indicates the maximum execution time, And Min indicates the minimum execution time.
Let's take a look at the performance of chrome18:
It consumes about 1/3 less time than ie10.
Because the registration method I call is Yahoo. tool. profiler. registerconstructor, which tests the uidraw object. If it is Yahoo. tool. profiler. if registerobject is used, only the registered objects, such as Yahoo. tool. profiler. registerobject ("ui1"); if you do not test the performance of ui2, You need to modify the code later. Set var report to Yahoo. tool. profiler. getfunctionreport ("uidraw. prototype. draw "); changed to VaR report = Yahoo. tool. profiler. getfunctionreport ("ui1.draw ");
The Code is as follows:
VaR ui1 = new uidraw ();
VaR ui2 = new uidraw ();
Yahoo. tool. profiler. registerobject ("ui1 ");
Ui1.draw ();
Ui2.draw ();
VaR report = Yahoo. tool. profiler. getfunctionreport ("ui1.draw ");
Console. Log (report)
you may wish to practice it yourself.