localStorage-string-size

JavaScript performance comparison

Test case created by Nicholas C. Zakas

Info

A benchmark to see if the size of strings stored in localStorage affects its read performance.

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;
var xlarge = large + large;

localStorage.setItem("a", small);
localStorage.setItem("b", medium);
localStorage.setItem("c", large);
localStorage.setItem("d", xlarge);
</script>
<script>
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 unknown unknown
Test Ops/sec
Read small value (100 chars)
var value = localStorage.getItem("a");
pending…
Read medium value (500 chars)
var value = localStorage.getItem("b");
pending…
Read large value (1000 chars)
var value = localStorage.getItem("c");
pending…
Read xlarge value (2000 chars)
var value = localStorage.getItem("d");
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