localStorage vs. WebSql

JavaScript performance comparison

Revision 20 of this test case created by Sebastiaan

Info

Tests the difference between operations with localStorage as compared to websql.

Preparation code

<script>
  var value = document.cookie;

  if (value.length) {
      localStorage.setItem("foo", document.cookie);
  } else {
      value = "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef";
      localStorage.setItem("foo", value);
      document.cookie = value;
  }
 
  var value;
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Reading from cookie
value = document.cookie;
pending…
Reading from localStorage getItem
value = localStorage.getItem('foo');
pending…
Writing to cookie
document.cookie = "bar=fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
pending…
Writing to localStorage property
localStorage.setItem("bar", "fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
pending…
read from websql
var db = openDatabase('mydb', '1.0', 'jsperf database', 2 * 1024 * 1024);
var id ="bar";
db.readTransaction(function (t) {
    t.executeSql('SELECT val FROM foo WHERE key = ?', [id], function (t, data) {
      value = data.rows.item(0).val;
    });
  });
pending…
write to websql
var db = openDatabase('mydb', '1.0', 'jsperf database', 2 * 1024 * 1024);
db.transaction(function (tx) {
  tx.executeSql('CREATE TABLE IF NOT EXISTS foo (key,val)');
  tx.executeSql('INSERT INTO foo (key, val) VALUES ("bar", "fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")');
});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment