const json = `{
"type": "widget-chart",
"title": "Handcrafted Wooden Sausages",
"data": {
"chart": {
"height": "100%",
"type": "donut"
},
"series": [
44,
55,
41,
17,
15
],
"responsive": [
{
"breakpoint": 480,
"options": {
"chart": {
"width": 200
},
"legend": {
"position": "bottom"
}
}
}
]
},
"_id": "5cf6307a245e2b001efd2111",
"id": "5cf6307a245e2b001efd2111"
}
`
console.time('eval')
let e = {}
eval('e = ' + json)
console.timeEnd('eval')
console.time('JSON.parse')
let p = {}
p = JSON.parse(json)
console.timeEnd('JSON.parse')
console.time('Function')
let f = {}
f = new Function('return ' + json)
console.timeEnd('Function')
eval: 0.209ms
JSON.parse: 0.046ms
Function: 0.085ms