localStorage vs. Objects (v26)

Revision 26 of this benchmark created by Rod Knowlton on


Description

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

Preparation HTML

<script>
  localStorage.setItem("foo", "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }");
  
  var FOO = {
   foo: "body { background: blue; margin: 10px; padding: 10px; color: black; text-decoration: none; }"
  };
  
  var value;

 var memoStorage = {
     cache: {},
     getItem: function(k) {
                    if(! this.cache[k]) {
                         this.cache[k] = localStorage.getItem(k);
                      }
                     return this.cache[k]
                          }
                   };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Reading from an object
value = FOO.foo;
ready
Reading from localStorage getItem
value = localStorage.getItem('foo');
ready
Reading from localStorage index
value = localStorage['foo'];
ready
Reading from localStorage property
value = localStorage.foo
ready
Memoized localStorage
value = memoStorage.getItem('foo')
ready

Revisions

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