localStorage vs. Objects (v34)

Revision 34 of this benchmark created on


Description

Tests the difference between reading from localStorage as compared to reading data from an object.

Preparation HTML

<script>
  var O = {};
  var cache = {
    storage: {},
    get: function (key) { return this.storage[key]; },
    set: function (key, value) { this.storage[key] = value; },
    clear: function () { this.storage = {}; }
  };
  localStorage.foo = "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }";
  O.foo = "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }";
  cache.set('foo', "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }");
  var value;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
value = O.foo;
ready
value = O['foo'];
ready
value = localStorage.foo;
ready
value = localStorage['foo'];
ready
value = localStorage.getItem('foo');
ready
value = cache.get('foo');
ready

Revisions

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