localstorage3

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  dummy = {}
  function setDummy (key, val) {
    dummy[key] = val
  }
  function readDummy (key) {
    return dummy[key]
  }
  
  function setLS (key, val) {
    localStorage.setItem(key, val)
  }
  function readLS (key) {
    return localStorage.getItem(key)
  }
  
  function makeSetKeys (count) {
    var s = []
    for (var i = 0; i < count; i++) {
      s.push("testKey" + i)
    }
    return s
  }
  function makeSetVals (count) {
    var s = []
    for (var i = 0; i < count; i++) {
      s.push("testValue" + i)
    }
    return s
  }
  kset1 = makeSetKeys(20)
  kset2 = makeSetKeys(200)
  vset1 = makeSetVals(20)
  vset2 = makeSetVals(200)
  
  for (var i = 0; i < kset2.length; i++) {
    setLS(kset2[i], vset2[i])
  }

};

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

};
</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
dummy-get-1
var ks = kset1
var vs = vset1
var fn = readDummy
for (var i = 0; i < ks.length; i++) {
  fn(ks[i], vs[i])
}
pending…
ls-get-1
var ks = kset1
var vs = vset1
var fn = readLS
for (var i = 0; i < ks.length; i++) {
  fn(ks[i], vs[i])
}
pending…
dummy-get-2
var ks = kset2
var vs = vset2
var fn = readDummy
for (var i = 0; i < ks.length; i++) {
  fn(ks[i], vs[i])
}
pending…
ls-get-2
var ks = kset2
var vs = vset2
var fn = readLS
for (var i = 0; i < ks.length; i++) {
  fn(ks[i], vs[i])
}
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