Skip to content

Instantly share code, notes, and snippets.

@sorenlouv
Created August 31, 2017 12:39
Show Gist options
  • Save sorenlouv/8d92751c2ba5367de7fd89c6d6e279ed to your computer and use it in GitHub Desktop.
Save sorenlouv/8d92751c2ba5367de7fd89c6d6e279ed to your computer and use it in GitHub Desktop.
Compare react perf
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