Serializing json vs. using 2 keys in localStorage

Benchmark created on


Description

The goal is to figure out if it's faster to serialize a simple object to json or use two keys in the storage.

We assume that we know exactly how the object has to be (de)serialized.

For that we serialize and unserialize the same object into localStorage. Once using two separated key and in the other case using JSON.

Setup

var toSerialize = {
      foo: 'bar',
      bar: 'foo'
    };
    var unSerialized;

Teardown


    localStorage.clear();
    delete unSerialized;
  

Test runner

Ready to run.

Testing in
TestOps/sec
localStorage using two keys
localStorage.setItem('foo', toSerialize.foo);
localStorage.setItem('bar', toSerialize.bar);
unSerialized = {
    foo: localStorage.getItem('foo'),
    bar: localStorage.getItem('bar')
};
 
ready
localStorage with JSON
localStorage.setItem('serialized', JSON.stringify(toSerialize));
unSerialized = JSON.parse(localStorage.getItem('serialized'));
ready

Revisions

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