Skip to content

Instantly share code, notes, and snippets.

@marekpiechut
Created June 22, 2021 10:52
Show Gist options
  • Select an option

  • Save marekpiechut/f2e0193249ee23ed2f3f1e2124d3d856 to your computer and use it in GitHub Desktop.

Select an option

Save marekpiechut/f2e0193249ee23ed2f3f1e2124d3d856 to your computer and use it in GitHub Desktop.
React-profiler
const ROUNDS = 100_000
const Benchmark = () => {
const [took, setTook] = useState()
const [round, setRound] = useState(1)
const start = useRef(performance.now())
useEffect(() => {
if (round < ROUNDS) {
setRound(round + 1)
} else {
setTook(performance.now() - start.current)
}
}, [round])
return (
<div className="App">
<div>{round}</div>
<div>Took: {took}ms</div>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment