variables inside functions

JavaScript performance comparison

Test case created by Sukima

Info

Is it better scope variables inside or outside a looped function?

Preparation code

<script src="http://underscorejs.org/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var outer_scoped, sample = new Array(10000);
};
</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
outer scoped
_.each(sample, function(v, i) {
  outer_scoped = "this is a test";
  sample[i] = outer_scoped.toUpperCase();
});
pending…
inner scoped
_.each(sample, function(v, i) {
  var inner_scoped = "this is a test";
  sample[i] = inner_scoped.toUpperCase();
});
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment