Created
June 22, 2021 10:53
-
-
Save marekpiechut/e0d1dd4ec008869b96afa3d35fcdd2b8 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