localStorage - setting multiple keys vs 1 big collection (v2)

Revision 2 of this benchmark created on


Setup

var collection = {
    key1: "foo",
    key2: "bar",
    key3: "baz",
    key4: "bah",
    key5: "hum",
    key6: "bug",
    key7: "abc",
    key8: "def",
    key9: "ghi"
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Setting Individual Keys
for (var key in collection) {
  localStorage.setItem(key, collection[key]);
}
ready
Setting a Collection
localStorage.setItem("all", JSON.stringify(collection));
ready
Getting Individual keys
for (var key in collection) {
  localStorage.getItem(key);
}
ready
Getting a Collection
JSON.parse(localStorage.getItem("all"));
ready
Getting a Key from a Collection
var all = JSON.parse(localStorage.getItem("all"));
var item;
for (var key in collection) {
  item = all[key];
}
ready

Revisions

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