localStorage String Size Retrieval

JavaScript performance comparison

Test case created by Nicholas C. Zakas

Preparation code

<script>
var small = "XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXXXXXX-";
var medium = small + small + small + small + small;
var large = medium + medium;

</script>
      
<script>
Benchmark.prototype.setup = function() {
  localStorage.setItem("a", small);
  localStorage.setItem("b", small);
  localStorage.setItem("c", small);
  localStorage.setItem("d", small);
  localStorage.setItem("e", small);
  localStorage.setItem("f", small);
  localStorage.setItem("g", small);
  localStorage.setItem("h", small);
  localStorage.setItem("i", small);
  localStorage.setItem("j", small);
  
  localStorage.setItem("z", large);

};

Benchmark.prototype.teardown = function() {
  localStorage.clear();

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Reading 10 small values
var value;
value = localStorage.getItem("a");
value = localStorage.getItem("b");
value = localStorage.getItem("c");
value = localStorage.getItem("d");
value = localStorage.getItem("e");
value = localStorage.getItem("f");
value = localStorage.getItem("g");
value = localStorage.getItem("h");
value = localStorage.getItem("i");
value = localStorage.getItem("j");
pending…
Reading one large value
var value;
value = localStorage.getItem("z");
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.

0 Comments