Created
June 22, 2021 10:52
-
-
Save marekpiechut/f2e0193249ee23ed2f3f1e2124d3d856 to your computer and use it in GitHub Desktop.
React-profiler
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 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