localStorage direct access vs native methods

Benchmark created by wookiehangover on


Description

Which is more performant, using array style or native methods for getting and setting localStorage keys?

Preparation HTML

<script src="//github.com/Modernizr/Modernizr/raw/master/modernizr.js"></script>
 
<script>
  var has_storage = Modernizr.localstorage;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
direct access set
if (has_storage) {

 localStorage['direct'] = "foo";

}
ready
native method set
if (has_storage) {

 localStorage.setItem("native", "foo");

}
ready
direct access get
if (has_storage) {

 var bar = localStorage['direct'];

}
ready
native method get
if (has_storage) {

 var bar = localStorage.getItem('native');

}
ready

Revisions

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

  • Revision 1: published by wookiehangover on