• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Measure Your Changes

Measurement is a key part of the optimization process. Use the simplest algorithms and data structures you can, and measure your code's performance to see whether you need to make any changes. Use timing commands or profilers to locate any bottlenecks. Optimize these hot spots one at a time, and measure any improvement. You can use the date object to time individual snippets:

<script type="text/javascript"> 
function DoBench(x){
    var startTime,endTime,gORl='local';
    if(x==1){
        startTime=new Date().getTime();
        Bench1();
        endTime=new Date().getTime();
    }else{
        gORl='global';
        startTime=new Date().getTime();
        Bench2();
        endTime=new Date().getTime();
    }
alert('Elapsed time using '+gORl+' variable: '+((endTime-startTime)/1000)+' seconds.');
}
...
</script>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint