localStorage - setting multiple keys vs 1 big collection

Benchmark created by Kevan Davis on


Description

Case 1: key1 = "foo" key2 = "bar" key3 = "baz"

Case 2: collection = { key1: "foo", key2: "bar", key3: "baz" }

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
for (var key in collection) {
  JSON.parse(localStorage.getItem("all"))[key];
}
ready

Revisions

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