localStorage vs. WebSql (v20)

Revision 20 of this benchmark created by Sebastiaan on


Description

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

Preparation HTML

<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

Ready to run.

Testing in
TestOps/sec
Reading from cookie
value = document.cookie;
ready
Reading from localStorage getItem
value = localStorage.getItem('foo');
ready
Writing to cookie
document.cookie = "bar=fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
ready
Writing to localStorage property
localStorage.setItem("bar", "fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
ready
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;
    });
  });
ready
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")');
});
ready

Revisions

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