1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    74
    Vote Rating
    0
    cwtuan is an unknown quantity at this point

      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 Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,572
    Vote Rating
    310
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      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

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi