Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hallo Welt
(version: 0)
Comparing performance of:
matchMedia + addListener vs normal thing
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<style> #before:before { content: "a"; display: none; } @media(min-width: 200px) { #body { background: red; content: "b"; } } @media(min-width: 600px) { #body { background: blue; content: "c"; } } @media(min-width: 1000px) { #body { background: yellow; content: "d"; } } </style> <div id="body"> </div>
Tests:
matchMedia + addListener
const matchMedia = window.matchMedia("(min-width: 400px)"); matchMedia.addListener((query) => { if (query.matches) { console.log(true); } })
normal thing
let currentWidth = window.innerWidth; window.addEventListener('resize', () => { if(window.innerWidth > 400) { console.log(true) } });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
matchMedia + addListener
normal thing
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
matchMedia vs clientWidth
matchMedia vs document.body.clientWidth
matchMedia vs cached matchMedia
Hallo Welt 123
Comments
Confirm delete:
Do you really want to delete benchmark?