I just wanna know,how I can get the execution time of my javascript code.For example I have any javascript code(loop,function etc..) I wanna know how much time takes to executing it.Or test my code how many operations it makes for example per second or minute.
            Asked
            
        
        
            Active
            
        
            Viewed 3,973 times
        
    -1
            
            
        - 
                    Have you tried Developer tools for Chrome? https://developer.chrome.com/devtools – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Jan 28 '15 at 13:25
4 Answers
3
            
            
        to calculate execution time use console.time (dev tools):
console.time("test");
//execute your code here
console.timeEnd("test");
 
    
    
        Kirill Pisarev
        
- 844
- 4
- 11
1
            
            
        you can do:
var startFrom = new Date().getTime();
//measured code here
console.log(new Date().getTime() - startFrom);
1
            
            
        You should try using a profiling system. If you use Google Chrome, for example, can hit ctrl-shift-i (Windows) or alt-command-i (OS X) and click on the Profiles tab. You can then select the Collect Javascript CPU Profile radio button and then hit start.
You'll find a bit more information here: https://developer.chrome.com/devtools/docs/cpu-profiling
 
    
    
        Michael Oryl
        
- 20,856
- 14
- 77
- 117
0
            
            
        The only thing I know about is Date:
var start = new Date().getTime();  //Time in ms
doSomething();
var end = new Date().getTime();
console.log("Operation took "+(end-start)+" miliseconds.");
But I suppose every browser has it's profiler allowing you to get more info. At least in firefox, there's a profiler if you press Ctrl+Shift+I. I nevr used it, so you must try it yourself.
 
    
    
        Tomáš Zato
        
- 50,171
- 52
- 268
- 778
 
    