Testing Browsers Javascript Engine

January 31, 2010

Problog

This post cover the following topics:

  • Song of the post
  • Code for testing Javascript engine
  • Results

Song of the Post – James Blackshaw – Cross

I decided to combine my two favorite things – javascript and music. So I’ll try to add a song which either i listened to during the writing of the post, or i just kept listening to it over and over so i decided to let you enjoy it as well (or not, your choice).

It is recommended to read the post while listening to the song (some say it is even better just to listen to the song, i’m just saying…)

So this post is hosting James Blackshaw, the gifted guitarist and pianist from London:

Couple of days ago a friend of mine came to watch a football (or as known to the Americans as soccer) game. The game was so boring that we started to talk about man stuff – who has the biggest, or in our case who is the fastest. After the game was over (thank god) i wanted to know which of the browsers has the most fastest javascript engine. i decided to run a little test of my own.

The Test Code

In order to test the javascript engine of each browser i created a page with an inline javascript code. i decided to check how each browser perform with string manipulation. I wrote two functions that do the same thing:


function strAdd1(){
    var start = new Date().valueOf();
    var str = "This is the string that will be tested. it is a long one with numbers 1234567890";
    for(var i=0;i<100000;i++){
        str += "This is the string that will be tested. it is a long one with numbers 1234567890";
    }
    return new Date().valueOf() - start;
}

function strAdd2(){
    var start = new Date().valueOf();
    var str = new Array();
    for(var i=0;i<100000;i++){
        str[str.length] = "This is the string that will be tested. it is a long one with numbers 1234567890";
    }
    var s = str.join("");
    return new Date().valueOf() - start;
}

function runTest(){
    var results = "Test Results<br>";
    results += "Time for string concotation: " + strAdd1() + "<br>";
    results += "Time for Array Join: " + strAdd2() + "<br>";
    document.getElementById("results").innerHTML = results;
}

addStr1 adds 10,000 times a string using regular string concatenation operator (+).
addStr2 creates an array and adds a new string to the end of the array 10,000 times. at the end it creates the same string as addStr1 does, using the join method. I know this is not the ultimate benchmark for javascript engine (nor even close) but i just wanted to validate my feelings about each browser.

I then ran the test on the following browsers:

  • firefox 3.5.7
  • IE8 8.0
  • safari 4.0.4
  • Chrome 4.0

The results

Browsers Javascript Engine Results

as you can see Chrome left all the others way behind, and to my surpriseĀ  firefox is lagging behind. What’s interesting to me is that i thought that the concatenation string (addStr1) would be much slower then strAdd2, but to my surprise it had much better results. I guess this is due to the fact that browser manufactures have really put an emphasis on javascript performance, and if we would test this code on IE6 and other old browser the picture would be much different.

So my friend won the argument but still, i’ll take firefox over any browser no matter how fast it is.

If you think of another function to add to the test, please write it in the comments to share it with everyone, and maybe i’ll add it to the post.
Cheers – and go Firefox!

Bookmark and Share
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Twitter

tags: , , , , , , ,
posted in Blog by Amir Harel

10 Comments to "Testing Browsers Javascript Engine"

  1. JavaScriptBank.com wrote:

    very cool & good post, thank you very much for sharing.

  2. Leslie_M wrote:

    Amir,

    It would be interesting to correlate your tests vs http://www2.webkit.org/perf/sunspider-0.9/sunsp…

    A few other tests would be interesting, if you have the time and interest in doing so. First would be Javascript crypto operations. Check out: http://crypto.stanford.edu/sjcl/

    Another would be DOM access and manipulation. e.g. how fast is each browser at getting a collection of elements and then extracting the values from them. See http://dromaeo.com/

  3. Amir Harel wrote:

    Thanks for the info.
    I might use it to write a more comprehensive Javascript engine benchmark.

  4. Amir Harel wrote:

    Thanks for the info.
    I might use it to write a more comprehensive Javascript engine benchmark.

  5. RONALD wrote:

    PillSpot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Vitamins@buy.online” rel=”nofollow”>.…

    Categories: Blood Pressure/Heart.Pain Relief.Skin Care.Antidiabetic.Stomach.Vitamins/Herbal Supplements.Antidepressants.Weight Loss.Womens Health.Eye Care.Mens Health.Stop SmokingAnxiety/Sleep Aid.Anti-allergic/Asthma.Mental HealthAntiviral.Antibi…

  6. FERNANDO wrote:


    PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. High quality drugs. Buy pills online

    Buy:Zovirax.100% Pure Okinawan Coral Calcium.Valtrex.Lumigan.Mega Hoodia.Arimidex.Human Growth Hormone.Prevacid.Synthroid.Petcam (Metacam) Oral Suspension.Zyban.Prednisolone.Actos.Accutane.Nexium.Retin-A….

  7. BRYAN wrote:


    MedicamentSpot.com. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Online Pharmacy. Buy pills online

    Buy:Ventolin.Female Cialis.Cozaar.Aricept.Zetia.SleepWell.Advair.Lasix.Lipitor.Nymphomax.Female Pink Viagra.Benicar.Buspar.Zocor.Seroquel.Acomplia.Wellbutrin SR.Amoxicillin.Lipothin.Prozac….

  8. CAMERON wrote:


    CheapTabletsOnline.Com. Canadian Health&Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. High quality pills. Buy drugs online

    Buy:Arimidex.Prednisolone.Mega Hoodia.Synthroid.Prevacid.Zovirax.Valtrex.Human Growth Hormone.Nexium.Zyban.100% Pure Okinawan Coral Calcium.Retin-A.Petcam (Metacam) Oral Suspension.Accutane.Lumigan.Actos….

  9. CHRISTOPHER wrote:


    CheapTabletsOnline.com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. Low price pills. Order drugs online

    Buy:VPXL.Cialis Professional.Viagra Super Active+.Viagra.Soma.Viagra Soft Tabs.Tramadol.Cialis Soft Tabs.Super Active ED Pack.Cialis Super Active+.Propecia.Viagra Super Force.Cialis.Viagra Professional.Zithromax.Maxaman.Levitra….

  10. MITCHELL wrote:


    NEW FASHION store. Original designers collection at low prices!!! 20 % TO 70 % OFF. END OF SEASON SALE!!!

    BUY FASHION. TOP BRANDS: GUCCI, DOLCE&GABBANA, BURBERRY, DIESEL, ICEBERG, ROBERTO CAVALLI, EMPORIO ARMANI, VERSACE…

 
Powered by Wordpress and MySQL. Theme by openark.org