Created
August 31, 2017 12:39
-
-
Save sorenlouv/8d92751c2ba5367de7fd89c6d6e279ed to your computer and use it in GitHub Desktop.
Compare react perf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LOCAL_STORAGE_KEY = 'react_perf_benchmark'; | |
function setBenchmark() { | |
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(Perf.getWasted())); | |
} | |
function compareBenchmark() { | |
const originalWasted = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
const newTable = Perf.getWasted() | |
.map(row => { | |
const originalRow = originalWasted.find(_row => row.key === _row.key); | |
const durationRelative = Math.round( | |
(originalRow.inclusiveRenderDuration - row.inclusiveRenderDuration) / | |
originalRow.inclusiveRenderDuration * | |
100 | |
); | |
const renderCountAbsolute = Math.round( | |
originalRow.renderCount - row.renderCount | |
); | |
return { | |
key: row.key, | |
durationRelative, | |
renderCountAbsolute, | |
currentDuration: row.inclusiveRenderDuration, | |
prevDuration: originalRow.inclusiveRenderDuration | |
}; | |
}) | |
.sort((a, b) => { | |
if (a.renderCountAbsolute < b.renderCountAbsolute) return 1; | |
if (a.renderCountAbsolute > b.renderCountAbsolute) return -1; | |
return 0; | |
}); | |
window.newTable = newTable; | |
console.table(newTable); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment