localStorage get/set vs dot notation

JavaScript performance comparison

Test case created by Dave

Info

Testing the speed of the getter and setter functions vs dot notation

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    target_size = 100;
    current = 0;
};

Benchmark.prototype.teardown = function() {
    current = 0;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
getItem null value
for (; current < target_size; current++) {
  localStorage.getItem('test');
}
pending…
getItem with value
localStorage.setItem('test', 1);
for (; current < target_size; current++) {
  localStorage.getItem('test');
}
pending…
dot notation fetch undefined
for (; current < target_size; current++) {
  localStorage.test;
}
pending…
dot notation get value
localStorage.setItem('test', 1);
for (; current < target_size; current++) {
  localStorage.test;
}
pending…
setItem
for (; current < target_size; current++) {
  localStorage.setItem('test', 1);
}
pending…
do notation set
for (; current < target_size; current++) {
  localStorage.test = 1;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment