UNPKG

@fromjs/backend

Version:
26 lines (25 loc) 885 B
"use strict"; // Show slow JSON.parse calls in the trace const nativeParse = JSON.parse; JSON.parse = function (json) { const shouldTrace = typeof json === "string" && json.length > 10; let start = new Date(); let ret = nativeParse.apply(this, arguments); if (shouldTrace) { const duration = new Date().valueOf() - start.valueOf(); if (duration > 20) { console.log("JSON.parse took " + duration + "ms", (json || "").slice(0, 100).replace(/\n/g, " ")); } } return ret; }; const nativeStringify = JSON.stringify; JSON.stringify = function () { let start = new Date(); const ret = nativeStringify.apply(JSON, arguments); let duration = new Date().valueOf() - start.valueOf(); if (duration > 20) { console.log("JSON.stringify took " + duration + "ms", (ret || "").slice(0, 100)); } return ret; };