test JSON.parse vs string splitting

Benchmark created on


Setup

const text = new Array(100000).fill(0).map(e => String.fromCharCode(Math.round(Math.random() * 250) + 40)).join("");

const header = {
title: "Some test",
created: Date.now(),
updated: Date.now(),
tags: ["something"],
};
const text1ToParse = JSON.stringify(header) + "\n\n" + text;
const text2ToParse = JSON.stringify({...header, text });

Test runner

Ready to run.

Testing in
TestOps/sec
Tiddler

const headerEnd = text1ToParse.indexOf("\n\n");
const fields = JSON.parse(text1ToParse.slice(0, headerEnd));
fields.text = text1ToParse.slice(headerEnd + 2);
ready
JSON

JSON.parse(text2ToParse)
ready

Revisions

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