JSON vs split/join for simple arrays

Benchmark created by Lea Verou on


Preparation HTML

<script>
  var numbers = [], booleans = [];
  
  for(var i=100; i--;) {
    numbers.push(Math.round(Math.random()));
    booleans.push(!!Math.round(Math.random()));
  }
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
The JSON way
JSON.parse(JSON.stringify(numbers));
JSON.parse(JSON.stringify(booleans));
ready
The split/join way
numbers.join().split(',');
booleans.join().split(',');
ready

Revisions

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

  • Revision 1: published by Lea Verou on