localStorage

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array = [{a:1,b:2,c:3},{a:1,b:2,c:3},{a:1,b:2,c:3}];
   
    localStorage.setItem('one',JSON.stringify(array));
   
    localStorage.setItem('deux_0',JSON.stringify(array[0]));
    localStorage.setItem('deux_1',JSON.stringify(array[1]));
    localStorage.setItem('deux_2',JSON.stringify(array[2]));
   
   
    sessionStorage.setItem('one',JSON.stringify(array));
};
</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
one localStorage
var s = localStorage.getItem('one');

var x = JSON.parse(s);
pending…
many localStorage
var deux_0 = localStorage.getItem('deux_0');

var xdeux_0 = JSON.parse(deux_0);

var deux_1 = localStorage.getItem('deux_1');

var xdeux_1 = JSON.parse(deux_1);

var deux_2 = localStorage.getItem('deux_2');

var xdeux_2 = JSON.parse(deux_2);
pending…
one LS / no JSON.parse
var s = localStorage.getItem('one');

var x = s;
pending…
many LS / no JSON.parse
var deux_0 = localStorage.getItem('deux_0');

var xdeux_0 = deux_0;

var deux_1 = localStorage.getItem('deux_1');

var xdeux_1 = deux_1;

var deux_2 = localStorage.getItem('deux_2');

var xdeux_2 = deux_2;
pending…
setItem stringify
localStorage.setItem('one',JSON.stringify(array))
pending…
setItem no stringify
localStorage.setItem('one',array)
pending…
sessionStorage setItem
sessionStorage.setItem('one',JSON.stringify(array))
pending…
sessionStorage getItem
sessionStorage.getItem('one')
pending…

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

Compare results of other browsers

0 comments

Add a comment