IndexedDB vs localStorage

JavaScript performance comparison

Test case created by Jens Arps

Preparation code

<script src="https://raw.github.com/jensarps/IDBWrapper/master/IDBStore.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var i = 0;
  
  var smallData = {
    'lastname': lastnames[Math.floor(Math.random()*5)],
    'firstanme': firstnames[Math.floor(Math.random()*4)],
    'dummyData': {}
  };
  
  var largeData = {
    'lastname': lastnames[Math.floor(Math.random()*5)],
    'firstanme': firstnames[Math.floor(Math.random()*4)],
    'dummyData': dummyData
  };

};
</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
localStorage read/write small data
smallData.id = ++i;
ls.setItem(smallData.id, JSON.stringify(smallData));
var value = JSON.parse(ls.getItem(smallData.id));
pending…
localStorage read/write large data
largeData.id = ++i;
ls.setItem(largeData.id, JSON.stringify(largeData));
var value = JSON.parse(ls.getItem(largeData.id));
pending…
IDB read/write small data
// async test
var value;
smallData.id = ++i;
idb.put(smallData, function(res){
  idb.get(smallData.id, function(res){
    value = res;
    deferred.resolve();
  });
});
pending…
IDB read/write large data
// async test
var value;
largeData.id = ++i;
idb.put(largeData, function(res){
  idb.get(largeData.id, function(res){
    value = res;
    deferred.resolve();
  });
});
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