localstorage

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  dummy = {}
  function setDummy (i) {
    dummy[i] = i + i + i
  }
  function readDummy (i) {
    return dummy[i]
  }
  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)
  

};
</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
dummy1
var s = set1
var fn = setDummy
for (var i = 0; i < s.length; i++) {
  fn(s[i])
}
pending…
ls1
var s = set1
var fn = setLS
for (var i = 0; i < s.length; i++) {
  fn(s[i])
}
pending…
dummy2
var s = set2
var fn = setDummy
for (var i = 0; i < s.length; i++) {
  fn(s[i])
}
pending…
ls2
var s = set2
var fn = setLS
for (var i = 0; i < s.length; i++) {
  fn(s[i])
}
pending…
dummy3-read-bias
var s = set1
var write = setDummy
var read = readDummy
var bias = 10
for (var i = 0; i < s.length; i++) {
  write(s[i])
}
for (var i = 0; i < s.length * bias; i++) {
  read(s[i / bias])
}
pending…
ls3-read-bias
var s = set1
var write = setLS
var read = readLS
var bias = 10
for (var i = 0; i < s.length; i++) {
  write(s[i])
}
for (var i = 0; i < s.length * bias; i++) {
  read(s[i / bias])
}
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