Test name | Executions per second |
---|---|
ResizeObserver | 4721.2 Ops/sec |
matchMedia | 4595.2 Ops/sec |
<div>
Hello
</div>
let value;
const observer = new ResizeObserver(entries => {
value = entries[0].contentRect.width;
})
observer.observe(document.body)
for (let i = 500; i <= 1920; i++) {
window.resizeTo(i, 1000)
}
let value;
const handleMatchChange = (val) => {
value = val;
}
const match1 = window.matchMedia('screen and (min-width: 800px)')
match1.addEventListener('change', handleMatchChange);
const match2 = window.matchMedia('screen and (min-width: 480px)')
match2.addEventListener('change', handleMatchChange);
const match3 = window.matchMedia('screen and (min-width: 1200px)')
match3.addEventListener('change', handleMatchChange);
for (let i = 500; i <= 1920; i++) {
window.resizeTo(i, 1000)
}