IndexedDB vs localStorage

JavaScript performance comparison

Revision 77 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()} });

let text = "a".repeat(1024);
data = [];
for (let index = 0; index < 100; index++) {
data.push(text + index);
}

localStorage.clear();
setTimeout(function() { 
for (let index = 0; index < data.length; index++) {
idb.put({data:data[index], id:""+index}, function(v) {1});
}
}, 2000);
localStorage.data = JSON.stringify(data);
</script>

    

Preparation code output

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
Read and write single Localstorage
data[0] = data[0];
localStorage.setItem('data', JSON.stringify(data));
var v = JSON.parse(localStorage.getItem('data'))[0];
pending…
Read All IDB
// async test
idb.getAll(function(v) {
    var string = v.join('\r\n');
    deferred.resolve();
});
pending…
Read All Local Storage
var v = JSON.parse(localStorage.getItem('data'));
var string = v.join('\r\n');
pending…
Read and Write Single IDB
// async test
idb.put({  data: data[0], id:"0" }, function(v) {
  idb.get("0", function(v) {    deferred.resolve();  }); 
});
pending…

Revisions

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

0 Comments