📍참고
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
performance.now() - Web APIs | MDN
The performance.now() method returns a high resolution timestamp in milliseconds. It represents the time elapsed since Performance.timeOrigin (the time when navigation has started in window contexts, or the time when the worker is run in Worker and Service
developer.mozilla.org
📍performance.now() 메서드
알고리즘 문제를 풀 때, 입력값의 최대 범위가 주어지면, O(N) 으로 해결 가능할지 테스트해보고 싶을 때가 있다
- 예) 1 <= N <= 1,000,000,000 (10억)
O(N) 으로 문제 해결 가능할지?
이 때 performance.now() 메서드를 활용한다
- ms 단위로 타임스탬프를 기록한다
const time1 = performance.now();
for (let i = 1; i <= 1_000_000_000; i++) {}
const time2 = performance.now();
console.log(time2 - time1); // 약 350ms