localStorage String Size 2

Benchmark created by Nicholas C. Zakas on


Description

Try to figure out if string size affects localStorage read performance.

Preparation HTML

<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;
</script>

Setup

var i;
    
    for (i=0; i < 10; i++){
        localStorage.setItem("value" + i, small);
    }
    
    
    for (; i < 20; i++){
        localStorage.setItem("value" + i, medium);
    }
    
    for (; i < 30; i++){
        localStorage.setItem("value" + i, large);
    }

Teardown


    localStorage.clear();
  

Test runner

Ready to run.

Testing in
TestOps/sec
Read small value (100 chars)
var index = Math.floor(Math.random() * 10),
    value = localStorage.getItem("value" + index);
ready
Read medium value (500 chars)
var index = Math.floor(Math.random() * 10) + 10,
    value = localStorage.getItem("value" + index);
ready
Read large value (1000 chars)
var index = Math.floor(Math.random() * 10) + 20,
    value = localStorage.getItem("value" + index);
ready

Revisions

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

  • Revision 1: published by Nicholas C. Zakas on