1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    62
    Vote Rating
    1
    cwtuan is on a distinguished road

      0  

    Default Performance of Ext.Array.each is better?

    Performance of Ext.Array.each is better?


    According to http://www.sencha.com/blog/ext-js-4-1-performance, it suggests using for (...) rather than Ext.Array.each.
    But, in my experiment, I am so surprised that Ext.Array.each has better performance than for (...). Why?

    PHP Code:
            var = [];        
            for ( var 
    0100000i++) {
                
    r.push(i);
            }

            
    time = new Date();
            for ( var 
    0r.lengthi++) {
            }
            
    console.log(new Date() - time); // 200 ms

            
    time = new Date();
            
    Ext.Array.each(r, function(rec) {
            });
            
    console.log(new Date() - time); // 55 ms 

  2. #2
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,338
    Vote Rating
    248
    skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of skirtle has much to be proud of

      0  

    Default


    Typing this directly into the console I saw the same thing. However, if I wrap it in a function the order switches.

    All sorts of possible reasons. Perhaps the JIT compiler can only work on functions. Or maybe it's because local variables are faster than globals. I haven't bothered digging any further.

    Try:

    Code:
    var fn = function() {
        var r = [], sum = 0, time;
    
        for (var i = 0 ; i < 100000 ; i++) {
            r.push(i);
        }
    
        time = new Date().getTime();
    
        Ext.Array.each(r, function(rec) {
            sum += rec;
        });
    
        console.log(sum, new Date().getTime() - time);
    
        sum = 0;
        time = new Date().getTime();
    
        for (var i = 0, len = r.length ; i < len ; i++) { // Note caching the length
            sum += r[i];
        }
    
        console.log(sum, new Date().getTime() - time);
    };
    
    fn();

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar