localstorage

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  dummy = {}
  function setDummy (i) {
    dummy[i] = i + i + i
  }
  function readDummy (i) {
    return dummy[i]
  }
  function readTest() {
    return readLS('test');
  }
  function setTest() {
    var test = set2.join(", ");
    return setLS('test','{['+test+']}');
  }
  function setLS (i) {
    localStorage.setItem(i, i + i + i)
  }
  function readLS (i) {
    return localStorage.getItem(i)
  }
  function makeSet (count) {
    var s = []
    for (var i = 0; i < count; i++) {
      s.push("" + i + i)
    }
    return s
  }
  set1 = makeSet(10)
  set2 = makeSet(100)

};

Benchmark.prototype.teardown = function() {
  dummy = {}
  function clearLocalStorage (s) {
    for (var i = 0; i < s.length; i++) {
      localStorage.removeItem(s[i])
    }
  }
  clearLocalStorage(set1)
  clearLocalStorage(set2)
  localStorage.removeItem('test')
  

};
</script>

Preparation code output

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
var s = set1
var fn = setDummy
for (var i = 0; i < s.length; i++) {
  fn(s[i])
}
pending…
ls1

pending…
dummy2
pending…
ls3-read-bias
pending…
ls-eval-loop
var write = setTest()
var read = readTest()

$.each($.parseJSON(read),function() {
  
});
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