loop-props

JavaScript performance comparison

Revision 2 of this test case created by Tobias Bosch

Preparation code

<input id="id1">
<script>
Benchmark.prototype.setup = function() {
    var counter = 0;
    var props = ['name','test'];
    var refProps = Object.getOwnPropertyNames(window.id1);
   
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for in
for (var prop in window.id1) {
  if (prop==='name') {
    counter++;
  }
}
return counter;
pending…
Object.getOwnPropertyNames
var props = Object.getOwnPropertyNames(id1);
for (var i=0; i<props.length; i++) {
  if (props[i]==='name') {
    counter++;
  }
}
return counter;
pending…
normal loop
for (var i=0; i<200; i++) {
  if (props[i]==='name') {
    counter++;
  }
}
return counter;
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