javascript 성능 테스트
Post

javascript 성능 테스트

javascript는 기본적으로 성능 테스트를 위한 performance.now() 메서드를 지원한다.
간단한 메서드 성능 테스트는 아래와 같이 쉽게 사용 가능하다.

Usage

1
2
3
4
5
6
7
8
9
10
const array = new Array(1000000).fill().map((_, i) => i)
let value = 0;

const t0 = performance.now();
for (let i=0; i<array.length; i++) {
    value += array[i];
}

const t1 = performance.now();
console.log(`took ${t1 - t0} ms`);