Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
MutationObserver: disconnect/reconnect vs. variable switch to avoid recursion
(version: 3)
Comparing performance of:
disconnect/reconnect with 1 observe vs disconnect/reconnect with 2 observes
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id="test">Test</div>
Script Preparation code:
const __OBSERVER = Symbol('observer'); const div = document.getElementById('test'); function update1() { if(!div[__OBSERVER]) { div[__OBSERVER] = new MutationObserver(mutations => update1()); } else { div[__OBSERVER].disconnect(); } div.style.opacity = parseInt(div.style.opacity) ? 0 : 1; div[__OBSERVER].observe(div, { attributeFilter: ['style'] }); } function update2() { if(!div[__OBSERVER]) { div[__OBSERVER] = new MutationObserver(mutations => update2()); } else { div[__OBSERVER].disconnect(); } div.style.opacity = parseInt(div.style.opacity) ? 0 : 1; div[__OBSERVER].observe(div, { attributeFilter: ['style'] }); div[__OBSERVER].observe(div, { characterData: true, subtree: true }); }
Tests:
disconnect/reconnect with 1 observe
update1();
disconnect/reconnect with 2 observes
update2();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
disconnect/reconnect with 1 observe
disconnect/reconnect with 2 observes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
disconnect/reconnect with 1 observe
1352938.2 Ops/sec
disconnect/reconnect with 2 observes
1073668.4 Ops/sec
Related benchmarks:
qwdqwdqwdqeqwdqw
Test getXAttrs
Test getXAttrs with type
contains vs closest fork
contains vs closest3
no-translate
no-translate2
Getting a context: closest vs while loop vs event propagation
Cost of adding and removing events
Comments
Confirm delete:
Do you really want to delete benchmark?