Skip to content

Instantly share code, notes, and snippets.

@Deraen
Created November 10, 2022 18:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Testing React vs Reagent update latency
(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