Created
November 10, 2022 18:45
-
-
Save Deraen/361c105108fa96c4ae7de58f3a85946e to your computer and use it in GitHub Desktop.
Testing React vs Reagent update latency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def start (atom nil)) | |
(def log (atom [])) | |
(defn latency-test [] | |
(let [a (r/atom 0)] | |
(fn [] | |
(let [[b update-b] (react/useState 0)] | |
(react/useEffect | |
(fn [] | |
(let [now (js/performance.now) | |
d (- now @start)] | |
(swap! log (fn [log] | |
(let [log (conj log d)] | |
(if (>= (count log) 100) | |
(do | |
(js/console.log (str/join "\n" log)) | |
[]) | |
log))))) | |
js/undefined)) | |
[:div | |
[:button | |
{:type "button" | |
:on-click (fn [e] | |
(reset! start (js/performance.now)) | |
(swap! a inc))} | |
"ratom"] | |
[:button | |
{:type "button" | |
:on-click (fn [e] | |
(reset! start (js/performance.now)) | |
(update-b inc))} | |
"hook"] | |
b | |
@a])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment