Why those Javascript snippets perform the same?

JavaScript performance comparison

Test case created

Info

http://stackoverflow.com/questions/14407099/why-those-javascript-snippets-perform-the-same#14407099

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    obj = [1,2,3,4,5];
    function iter(){
        for (var key in obj){
            key=key+key;
        };
    };
    function test1() {
        iter(obj);
    };
    function test2(){
        (function iter(obj){
            for (var key in obj){
                key=key+key;
            };
        })(obj);    
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
function
test1()
 
pending…
anonymous function
test2()
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment