Immutable Record Performance

JavaScript performance comparison

Test case created by Doug Day

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var SubRecord = Immutable.Record({
      other: true
  });
  
  var MyRecord = Immutable.Record({
      id: 0,
      name: "",
      sub: SubRecord()
  });
  
  var sampleRecord = MyRecord({id: 1, name: "Test", sub: SubRecord({ other: false })});
  var sampleMap = Immutable.fromJS({
       id: 1, 
       name: "Test",
       sub: { other: false }
  });
  
  function accessRecord() {
      var id = sampleRecord.id;
      var name = sampleRecord.name;
      var other = sampleRecord.sub.other;
  }
  
  function accessMap() {
      var id = sampleMap.get("id");
      var name = sampleMap.get("name");
      var other = sampleMap.getIn(["sub", "other"]);
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Instantiate predefined Record
var record = MyRecord({id: 1, name: "Test", sub: SubRecord({ other: false })});
pending…
Create Record on-the-fly
var record = Immutable.Record({
    id: 0,
    name: "",
    sub: Immutable.Record({
        other: true,
    })
})({id: 1, name: "Test", sub: {other: false}});
pending…
FromJS
var map = Immutable.fromJS({
     id: 1, 
     name: "Test",
     sub: { other: false }
});
pending…
Access records
accessRecord();
pending…
Access maps
accessMap();
pending…

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

0 Comments