localStorage vs WebSQL (v14)

Revision 14 of this benchmark created on


Description

This tests localStorage performance against WebSQL. localStorage tests contain JSON stringify/parse methods.

Preparation HTML

<script>
  var small, large, idb, websql, ls;

  // data setup
  small = 'test';
  large = '';
  for (var i = 0; i < 10000; i++) large += '1234567890';

  // store setup
  window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
  var request = indexedDB.open("benchmark");
  request.onsuccess = function(e) {
    var v = "1.0";
    idb = e.target.result;
    if (v != idb.version) {
      var setVrequest = idb.setVersion(v);
      setVrequest.onsuccess = function(e) {
        var store = idb.createObjectStore("benchmark");
        e.target.transaction.oncomplete = function() {
          var trans = idb.transaction(["benchmark"], "readwrite");
          var store = trans.objectStore("benchmark");
          store.add(small, 1);
          store.add(large, 2);
        };
      };
    };
  };

  ls = window.localStorage;
  ls.clear();
  ls[1] = small;
  ls[2] = large;

  websql = openDatabase('benchmark', '1.0', '', 1 * 1024 * 1024);
  websql.transaction(function(tx) {
    tx.executeSql('DROP TABLE IF EXISTS benchmark;');
    tx.executeSql('CREATE TABLE benchmark (id, value);');
    tx.executeSql('INSERT INTO benchmark (id, value) VALUES (?, ?)', [1, small]);
    tx.executeSql('INSERT INTO benchmark (id, value) VALUES (?, ?)', [2, large]);
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
localStorage read small data
var value = ls[1];
ready
localStorage read large data
var value = ls[2];
ready
WebSQL read small data
// async test
websql.transaction(function(tx) {
  tx.executeSql('SELECT * FROM benchmark WHERE id=?', [1], function(t1, r1) {
    deferred.resolve();
  });
});
ready
WebSQL read large data
// async test
websql.transaction(function(tx) {
  tx.executeSql('SELECT * FROM benchmark WHERE id=?', [2], function(t1, r1) {
    deferred.resolve();
  });
});
ready

Revisions

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