localStorage vs WebSQL
JavaScript performance comparison
Info
This tests localStorage performance against WebSQL. localStorage tests contain JSON stringify/parse methods.
Preparation code
<script>
var small, large, idb, websql, ls;
// data setup
small = 'test';
large = '';
for (var i = 0; i < 10000; i++) large += '1234567890';
// store setup
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
var request = indexedDB.open("benchmark");
request.onsuccess = function(e) {
var v = "1.0";
idb = e.target.result;
if (v != idb.version) {
var setVrequest = idb.setVersion(v);
setVrequest.onsuccess = function(e) {
var store = idb.createObjectStore("benchmark");
e.target.transaction.oncomplete = function() {
var trans = idb.transaction(["benchmark"], "readwrite");
var store = trans.objectStore("benchmark");
store.add(small, 1);
store.add(large, 2);
};
};
};
};
ls = window.localStorage;
ls.clear();
ls[1] = small;
ls[2] = large;
websql = openDatabase('benchmark', '1.0', '', 1 * 1024 * 1024);
websql.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS benchmark;');
tx.executeSql('CREATE TABLE benchmark (id, value);');
tx.executeSql('INSERT INTO benchmark (id, value) VALUES (?, ?)', [1, small]);
tx.executeSql('INSERT INTO benchmark (id, value) VALUES (?, ?)', [2, large]);
});
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
localStorage read small data |
|
pending… |
localStorage read large data |
|
pending… |
WebSQL read small data |
|
pending… |
WebSQL read large data |
|
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:
- Revision 4: published
- Revision 5: published
- Revision 6: published by Alex
- Revision 7: published
- Revision 13: published
- Revision 14: published
- Revision 15: published by Marc
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 22: published
- Revision 24: published
0 comments