json grep vs json by key (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

Setup

var json1 = {
      item1: "value1",
      item2: "value2",
      item3: "value3",
      item4: "value4",
      item5: "value5",
      item6: "value6",
      item7: "value7",
      item8: "value8",
      item9: "value9",
      item10: "value10"
    }
    
    var json2 = [{
      sn: "item1",
      val: "value1"
    }, {
      sn: "item2",
      val: "value2"
    }, {
      sn: "item3",
      val: "value3"
    }, {
      sn: "item4",
      val: "value4"
    }, {
      sn: "item5",
      val: "value5"
    }, {
      sn: "item6",
      val: "value6"
    }, {
      sn: "item7",
      val: "value7"
    }, {
      sn: "item8",
      val: "value8"
    }, {
      sn: "item9",
      val: "value9"
    }, {
      sn: "item10",
      val: "value10"
    }];

Test runner

Ready to run.

Testing in
TestOps/sec
json by key
for (var i = 0; i < 1000; i++) {
  console.log(json1.item10);
}
ready
json grep
for (var i = 0; i < 1000; i++) {
  console.log($.grep(json2, function(n) {
    return (n.sn == "item10");
  })[0].val);
}
ready

Revisions

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