Friday, March 25, 2011

JavaScript Engine Performance: IE 9.0, Safari 5.0, Chrome 10.0, FireFix 5.0, Opera 11.

Which one of this JavaScript engine is the fastest?
This test worth only what is worth as it only execute a very limited subset of the JavaScript language, but it should give us a first indication.

This is my first test, I will replace the test code with something more demanding in the future.

First the source code
function print(s){
    var oldValue = jQuery("#Output").val();
    oldValue    += "\r\n" + s;
    jQuery("#Output").val(oldValue);
}
function Fibonnaci(n){

    var previous = -1;
    var result   =  1;

    for(var i=0; i < n+1; i++){

        var sum  = result + previous;
        previous = result;
        result   = sum;
    }
    return result;
}
function Test() {
    try {
        print("Running...");

        var startTime = new Date().getTime();

        for (var t = 0; t < 1000; t++) {

            for (var i = 0; i < 1000; i++) {

                var v = Fibonnaci(i);
            }
        }
        var endTime = new Date().getTime();
        var time = (endTime - startTime)/1000;
        print("Duration:" + time);
    }
    catch (ex) {
        alert(ex);
    }
}
Here is the result in seconds.
BrowserExecution TimePerformance Compared To Chrome
IE 97.39.1 slower
Safari 54.35.4 slower
Opera 114.55.6 slower
Firefox 43.64.5 slower
Chrome 100.8same
Now I know why I prefer Chrome.

No comments:

Post a Comment