function diffDatabases(db1, db2, filter) {
  var ALIGN_RIGHT = -8; // 8 chars wide, right aligned

  // Build event data tables.
  var table1 = new wtf.db.EventStatistics(db1).getTable();
  var table2 = new wtf.db.EventStatistics(db2).getTable();

  if (filter) {
    table1 = table1.filter(filter);
    table2 = table2.filter(filter);
  }

  // Grab all event types from each table and divide by type.
  var allInstanceEntryNames = wtf.db.EventStatistics.getAllEventTypeNames(
      [table1, table2], wtf.data.EventClass.INSTANCE);
  var allScopeEntryNames = wtf.db.EventStatistics.getAllEventTypeNames(
      [table1, table2], wtf.data.EventClass.SCOPE);

  // Dump scope events.
  console.log(util.spaceValues(
      [ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT],
      'Count', 'Total', 'Average'));
  console.log('');
  allScopeEntryNames.sort(function(nameA, nameB) {
    var entryA1 = table1.getEventTypeEntry(nameA);
    var entryA2 = table2.getEventTypeEntry(nameA);
    var diffA = Math.abs((entryA1 ? entryA1.getMeanTime() : 0) -
                         (entryA2 ? entryA2.getMeanTime() : 0));
    var entryB1 = table1.getEventTypeEntry(nameB);
    var entryB2 = table2.getEventTypeEntry(nameB);
    var diffB = Math.abs((entryB1 ? entryB1.getMeanTime() : 0) -
                         (entryB2 ? entryB2.getMeanTime() : 0));
    return diffA - diffB;
  });
  for (var n = 0; n < allScopeEntryNames.length; n++) {
    var eventTypeName = allScopeEntryNames[n];
    var entry1 = table1.getEventTypeEntry(eventTypeName);
    var entry2 = table2.getEventTypeEntry(eventTypeName);
    var hasEntry1 = entry1 && entry1.getCount();
    var hasEntry2 = entry2 && entry2.getCount();
    if (!hasEntry1 && !hasEntry2) {
      continue;
    }

    var diff =
        (hasEntry1 ? entry1.getMeanTime() : 0) -
        (hasEntry2 ? entry2.getMeanTime() : 0);
    var color = '';
    if (diff < 0) {
      color = '\033[31m';
    } else if (diff > 0) {
      color = '\033[32m';
    }

    console.log(color + eventTypeName + '\033[0m');
    if (hasEntry1) {
      console.log(util.spaceValues(
          [ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT],
          String(entry1.getCount()),
          wtf.util.formatSmallTime(entry1.getUserTime()),
          wtf.util.formatSmallTime(entry1.getMeanTime())));
    } else {
      console.log('(not present in input 1)');
    }
    if (hasEntry2) {
      console.log(util.spaceValues(
          [ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT],
          String(entry2.getCount()),
          wtf.util.formatSmallTime(entry2.getUserTime()),
          wtf.util.formatSmallTime(entry2.getMeanTime())));
    } else {
      console.log('(not present in input 2)');
    }
    console.log('');

    // drawDistribution(entry1.getDistribution());
    // drawDistribution(entry2.getDistribution());
  }

  db1.dispose();
  db2.dispose();
  return 0;
}
Diffs two loaded databases.
@param {!wtf.db.Database} db1 Database 1.
@param {!wtf.db.Database} db2 Database 2.
@param {wtf.db.Filter} filter Filter, if any.