For vs each

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<form id="isinListForm">
  <table>
    <tr>
      <td>
        1111
      </td>
    </tr>
    <tr>
      <td>
        <input type="text" name="isin" class="isinInput isin-code" value="1" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="text" name="isin" class="isinInput isin-code" value="2" />
      </td>
    </tr>
  </table>
</form>

Preparation code output

1111

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
var arr = [];
var listIsin = $("#isinListForm").find("input.isinInput");
for (var i = 0; i < listIsin.size(); ++i) {
  var val = listIsin[i].value;
  if ($.trim(val) != "") {
    var isin = {};
    isin.value = val;
    isin.status = $(this).attr("isinStatus");
    arr.push(isin);
  }
}
pending…
each
var arr = [];
$.each($("input.isinInput"), function() {
  var val = $(this).val();
  if ($.trim(val) != "") {
    var isin = {};
    isin.value = val;
    isin.status = $(this).attr("isinStatus");
    arr.push(isin);
  }
});
pending…
for returned
var arr = [];
var listIsin = $("#isinListForm").find("input.isinInput");
for (var i = listIsin.size(); i > 0; --i) {
  var val = listIsin[i - 1].value;
  if ($.trim(val) != "") {
    var isin = {};
    isin.value = val;
    isin.status = $(this).attr("isinStatus");
    arr.push(isin);
  }
}
pending…
spliced
var arr = [];
var listIsin = $("#isinListForm").find("input.isinInput");
for (var i = listIsin.size(); i > 0; --i) {
  var val = listIsin.shift();
  if ($.trim(val) != "") {
    var isin = {};
    isin.value = val;
    isin.status = $(this).attr("isinStatus");
    arr.push(isin);
  }
}
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