Angular Calendar Events Fingerprint

JavaScript performance comparison

Revision 3 of this test case created by Gleb Mazovetskiy

Info

Due to the way angular 2-way data binding synchronisation works (i.e. full dirty-checking for all bindings), we need to have an extremely fast way of comparing calendar events.

This compares the slightly different way of computing a fingerprint of a dataset, in order to find the fastest one for all browsers.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var events = [];
    for (var i = 0; i < 1000; i++) {
      var e = {};
      e.title = "Test event";
      e.start = new Date();
      e.end  = new Date();
      events.push(e);
    }
};
</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
[attr1, attr2, ...].join("")
var fingerprint = (function() {
  var fpn = [];
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn.push(e.id, e.title, e.url, e.start, e.end, e.allDay);
  }
  return fpn.join("")
})();
(fingerprint === fingerprint);
pending…
[attr1, attr2, ...].join("") (pre-init array)
var fingerprint = (function() {
  var fpn = new Array(events.length);
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn.push(e.id, e.title, e.url, e.start, e.end, e.allDay);
  }
  return fpn.join("")
})();
(fingerprint === fingerprint);
pending…
"" + attr1 + attr2 ...
var fingerprint = (function() {
  var fpn = "";
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn = fpn + e.id + e.title + e.url + e.start + e.end + e.allDay;
  }
  return fpn;
})();
(fingerprint === fingerprint);
pending…
"".concat(attr1, attr2, ...)
var fingerprint = (function() {
  var fpn = "";
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn = fpn.concat(e.id, e.title, e.url, e.start, e.end, e.allDay);
  }
  return fpn;
})();
(fingerprint === fingerprint);
pending…
"" + attr1 + attr2 ... (convert dates)
var fingerprint = (function() {
  var fpn = "";
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn = fpn + e.id + e.title + e.url + (+e.start) + (+e.end) + e.allDay;
  }
  return fpn;
})();
(fingerprint === fingerprint);
pending…
"" + attr1 + attr2 ... (convert dates, explicit empty string)
var fingerprint = (function() {
  var fpn = "";
  for (var i = 0, n = events.length; i < n; i++) {
    var e = events[i];
    fpn = fpn + (e.id || '') + (e.title || '') + (e.url || '') + (+e.start || '') + (+e.end || '') + (e.allDay || false);
  }
  return fpn;
})();
(fingerprint === fingerprint);
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