mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
📎 Update frontend bench tools
This commit is contained in:
parent
7fa24fdc2f
commit
121188d921
2 changed files with 101 additions and 55 deletions
|
@ -3,63 +3,95 @@
|
|||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes.rect :as gsr]
|
||||
[app.common.perf :as perf]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.shapes.transforms :as gst]
|
||||
[app.common.record :as cr]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.rect_impl :as grci]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.test.check.generators :as gen]))
|
||||
[app.common.types.shape :as cts]
|
||||
[app.util.perf :as perf]))
|
||||
|
||||
(def points
|
||||
(gen/sample (s/gen ::gpt/point) 20))
|
||||
|
||||
(defn bench-points
|
||||
(defn random
|
||||
[]
|
||||
#_(perf/benchmark
|
||||
:f #(gpt/center-points-old points)
|
||||
:samples 20
|
||||
:max-iterations 500000
|
||||
:name "base")
|
||||
(perf/benchmark
|
||||
:f #(gpt/center-points points)
|
||||
:max-iterations 500000
|
||||
:samples 20
|
||||
:name "optimized"))
|
||||
(js/Math.random))
|
||||
|
||||
(def modifiers
|
||||
(-> (ctm/empty)
|
||||
(ctm/move (gpt/point 100 200))
|
||||
(ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
(ctm/move (gpt/point -100 -200))
|
||||
(ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
(ctm/rotation (gpt/point 0 0) -100)
|
||||
(ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))))
|
||||
|
||||
(defn bench-modifiers
|
||||
(defn force-gc
|
||||
[]
|
||||
(perf/benchmark
|
||||
:f #(ctm/modifiers->transform modifiers)
|
||||
:max-iterations 50000
|
||||
:samples 20
|
||||
:name "current")
|
||||
(js/gc))
|
||||
|
||||
#_(perf/benchmark
|
||||
:f #(ctm/modifiers->transform-2 modifiers)
|
||||
:max-iterations 50000
|
||||
:samples 20
|
||||
:name "optimized"))
|
||||
;; (defn bench-modifiers
|
||||
;; []
|
||||
;; (println "")
|
||||
;; (println "===> BENCH MODIFIERS <===")
|
||||
;; (let [modifiers (-> (ctm/empty)
|
||||
;; (ctm/move (gpt/point 100 200))
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
;; (ctm/move (gpt/point -100 -200))
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
;; (ctm/rotation (gpt/point 0 0) -100)
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5)))]
|
||||
;; (perf/benchmark
|
||||
;; :gc force-gc
|
||||
;; :iterations 50000
|
||||
;; :name "modifiers->transform:old"
|
||||
;; :run-fn #(ctm/modifiers->transform-old modifiers))
|
||||
|
||||
;; (perf/benchmark
|
||||
;; :gc force-gc
|
||||
;; :iterations 50000
|
||||
;; :name "modifiers->transform:new"
|
||||
;; :run-fn #(ctm/modifiers->transform modifiers))))
|
||||
|
||||
|
||||
;; (defn bench-apply-transform
|
||||
;; []
|
||||
;; (println "")
|
||||
;; (println "===> BENCH APPLY TRANFORM <===")
|
||||
;; (let [modifiers (-> (ctm/empty)
|
||||
;; (ctm/move (gpt/point 100 200))
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
;; (ctm/move (gpt/point -100 -200))
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5))
|
||||
;; (ctm/rotation (gpt/point 0 0) -100)
|
||||
;; (ctm/resize (gpt/point 100 200) (gpt/point 2.0 0.5)))
|
||||
;; transform (ctm/modifiers->transform modifiers)
|
||||
|
||||
;; shape (cts/setup-shape {:type :rect
|
||||
;; :x 0
|
||||
;; :y 0
|
||||
;; :width 10
|
||||
;; :height 10})]
|
||||
|
||||
;; ;; (app.common.pprint/pprint shape)
|
||||
|
||||
;; (perf/benchmark
|
||||
;; :gc force-gc
|
||||
;; :iterations 400
|
||||
;; :name "apply-transform:old"
|
||||
;; :run-fn #(gst/apply-transform shape modifiers))
|
||||
|
||||
;; (perf/benchmark
|
||||
;; :gc force-gc
|
||||
;; :iterations 400
|
||||
;; :name "apply-transform:new"
|
||||
;; :run-fn #(gst/apply-transform' shape modifiers))
|
||||
;; ))
|
||||
|
||||
;; (ctm/modifiers->transform-2 modifiers)
|
||||
|
||||
(defn ^:dev/after-load after-load
|
||||
[]
|
||||
#_(bench-modifiers))
|
||||
;; (bench-apply-transform)
|
||||
;; (let [o (grc/make-rect 1 1 10 10)]
|
||||
;; (prn o)
|
||||
;; (prn (-> o
|
||||
;; (cr/assoc! :x 40)
|
||||
;; (grc/update-rect! :size)))
|
||||
;; )
|
||||
)
|
||||
|
||||
(defn main
|
||||
[& [name]]
|
||||
(case name
|
||||
"points" (bench-points)
|
||||
"modifiers" (bench-modifiers)
|
||||
(println "available: points"))
|
||||
#_(.exit js/process 0))
|
||||
|
||||
[& params]
|
||||
;; (bench-apply-transform)
|
||||
;; (bench-apply-transform)
|
||||
nil)
|
||||
|
|
|
@ -107,26 +107,40 @@
|
|||
children)))
|
||||
|
||||
(defn benchmark
|
||||
[& {:keys [f warmup iterations name]
|
||||
[& {:keys [run-fn chk-fn iterations name gc]
|
||||
:or {iterations 10000}}]
|
||||
(let [end-mark (str name ":end")]
|
||||
(let [end-mark (str name ":end")
|
||||
blackhole (volatile! nil)]
|
||||
(println "=> benchmarking:" name)
|
||||
(println "--> warming up:" iterations)
|
||||
(loop [i iterations]
|
||||
(when gc
|
||||
(println "-> force gc: true"))
|
||||
|
||||
(println "--> warming up: " (* iterations 2))
|
||||
(when (fn? gc) (gc))
|
||||
(loop [i (* iterations 2)]
|
||||
(when (pos? i)
|
||||
(f)
|
||||
(vreset! blackhole (run-fn))
|
||||
(recur (dec i))))
|
||||
(println "--> benchmarking:" iterations)
|
||||
(when (fn? gc) (gc))
|
||||
(js/performance.mark name)
|
||||
(loop [i iterations]
|
||||
(when (pos? i)
|
||||
(f)
|
||||
(vreset! blackhole (run-fn))
|
||||
(recur (dec i))))
|
||||
(js/performance.measure end-mark name)
|
||||
|
||||
(when (fn? chk-fn)
|
||||
(when-not (chk-fn @blackhole)
|
||||
(println "--> EE: failed chk-fn")))
|
||||
|
||||
|
||||
(let [[result] (js/performance.getEntriesByName end-mark)
|
||||
duration (mth/precision (.-duration ^js result) 4)
|
||||
avg (mth/precision (/ duration iterations) 4)]
|
||||
(println "--> TOTAL:" (str duration "ms") "AVG:" (str avg "ms"))
|
||||
(println "--> TOTAL:" (str duration " ms"))
|
||||
(println "--> AVG :" (str avg " ms"))
|
||||
(println "")
|
||||
(js/performance.clearMarks name)
|
||||
(js/performance.clearMeasures end-mark)
|
||||
#js {:duration duration
|
||||
|
|
Loading…
Add table
Reference in a new issue