JSFiddle - React, Tailwind, and code Playground

by crucify

HTML

<p>
/\s/g 보다 /\s+/g 가 훨씬 빠릅니다.
</p>
<p>
작은 단위의 loop 에서 최대한 필터링 하여 큰 단위의 loop 을 줄여주는 것이 효과가 좋기 때문이라 생각됩니다.
</p>
<p id="result">

</p>

JavaScript

let t = [], res = [];
t.push(Date.now());
for(let i = 0; i < 10000000; i ++) "asdf   z      xcv qwer".replace(/\s/g, '');
t.push(Date.now());
res.push('/\\s/g 테스트(ms) : ' + (t[1] - t[0]));

for(let i = 0; i < 10000000; i ++) "asdf   z      xcv qwer".replace(/\s+/g, '');
t.push(Date.now());
res.push('/\\s+/g 테스트(ms) : ' + (t[2] - t[1]));

for(let i = 0; i < 10000000; i ++) "asdf   z      xcv qwer".replace(/\s/g, '');
t.push(Date.now());
res.push('/\\s/g 재 테스트(ms) : ' + (t[3] - t[2]));

document.getElementById('result').innerHTML = res.join('<br>');