Add general performance micro optimizations

This commit is contained in:
Andrey Antukh 2023-05-14 18:55:11 +02:00 committed by Alonso Torres
parent 78f62cc5e1
commit b7e1e54a92
4 changed files with 45 additions and 25 deletions

View file

@ -48,7 +48,7 @@
(defn duration
[o]
(cond
(integer? o) (.fromMillis Duration o)
(number? o) (.fromMillis Duration o)
(duration? o) o
(string? o) (.fromISO Duration o)
(map? o) (.fromObject Duration (clj->js o))
@ -239,6 +239,25 @@
(when v
(let [v (if (datetime? v) (format v :date) v)
locale (obj/get locales locale)
f (-> (.-formatLong ^js locale)
(.date v))]
(dateFnsFormat v f #js {:locale locale})))))
f (.date (.-formatLong locale) v)]
(->> #js {:locale locale}
(dateFnsFormat v f))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Measurement Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn tpoint
"Create a measurement checkpoint for time measurement of potentially
asynchronous flow."
[]
(let [p1 (.now js/performance)]
#(duration (- (.now js/performance) p1))))
(defn tpoint-ms
"Create a measurement checkpoint for time measurement of potentially
asynchronous flow."
[]
(let [p1 (.now js/performance)]
#(- (.now js/performance) p1)))