IndexedDB vs localStorage

JavaScript performance comparison

Revision 67 of this test case created by

Preparation code

<script src="https://rawgithub.com/jensarps/IDBWrapper/master/idbstore.js"></script>
<script>
var idb = new IDBStore({ dbName: 'perf', storeName: 'perf',  dbVersion: '1.0',  keyPath: 'id',  autoIncrement: true,  onStoreReady:function(){idb.clear()} });
data128 = "a".repeat(1024).repeat(128);
data512 = data128.repeat(4);
localStorage.clear();
setTimeout(function() { 
idb.put({data:data128, id:"ro128"}, function(v) {1});
idb.put({data:data512, id:"ro512"}, function(v) {1});
}, 2000);
localStorage.ro128 = data128;
localStorage.ro512 = data512;
</script>

    

Preparation code output

<script> var idb = new IDBStore({ dbName: 'perf', storeName: 'perf', dbVersion: '1.0', keyPath: 'id', autoIncrement: true, onStoreReady:function(){idb.clear()} }); data128 = "a".repeat(1024).repeat(128); data512 = data128.repeat(4); localStorage.clear(); setTimeout(function() { idb.put({data:data128, id:"ro128"}, function(v) {1}); idb.put({data:data512, id:"ro512"}, function(v) {1}); }, 2000); localStorage.ro128 = data128; localStorage.ro512 = data512; </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
IDB r/w 128KB
// async test
idb.put({  data:data128, id:"rw128" }, function(v) {
  idb.get("rw128", function(v) {    deferred.resolve();  }); 
});
pending…
localStorage r/w 128KB + stringify
localStorage.setItem(0, JSON.stringify(data128));
var v = localStorage.getItem(0);
pending…
localStorage r/w 128KB no stringify
localStorage.setItem(1, data128);
var v = localStorage.getItem(1);
pending…
IDB ro 128KB
// async test
idb.get("ro128", function(v) {    deferred.resolve();});
pending…
IDB ro 512KB
// async test
idb.get("ro512", function(v) {    deferred.resolve();});
pending…
localStorage ro 128KB
var v = localStorage.getItem("ro128");
pending…
localStorage ro 512KB
var v = localStorage.getItem("ro512");
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.

0 Comments