mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -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 :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.shapes.rect :as gsr]
|
[app.common.geom.shapes.transforms :as gst]
|
||||||
[app.common.perf :as perf]
|
[app.common.record :as cr]
|
||||||
|
[app.common.geom.rect :as grc]
|
||||||
|
[app.common.geom.rect_impl :as grci]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
[clojure.spec.alpha :as s]
|
[app.common.types.shape :as cts]
|
||||||
[clojure.test.check.generators :as gen]))
|
[app.util.perf :as perf]))
|
||||||
|
|
||||||
(def points
|
(defn random
|
||||||
(gen/sample (s/gen ::gpt/point) 20))
|
|
||||||
|
|
||||||
(defn bench-points
|
|
||||||
[]
|
[]
|
||||||
#_(perf/benchmark
|
(js/Math.random))
|
||||||
: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"))
|
|
||||||
|
|
||||||
(def modifiers
|
(defn force-gc
|
||||||
(-> (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
|
|
||||||
[]
|
[]
|
||||||
(perf/benchmark
|
(js/gc))
|
||||||
:f #(ctm/modifiers->transform modifiers)
|
|
||||||
:max-iterations 50000
|
|
||||||
:samples 20
|
|
||||||
:name "current")
|
|
||||||
|
|
||||||
#_(perf/benchmark
|
;; (defn bench-modifiers
|
||||||
:f #(ctm/modifiers->transform-2 modifiers)
|
;; []
|
||||||
:max-iterations 50000
|
;; (println "")
|
||||||
:samples 20
|
;; (println "===> BENCH MODIFIERS <===")
|
||||||
:name "optimized"))
|
;; (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
|
(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
|
(defn main
|
||||||
[& [name]]
|
[& params]
|
||||||
(case name
|
;; (bench-apply-transform)
|
||||||
"points" (bench-points)
|
;; (bench-apply-transform)
|
||||||
"modifiers" (bench-modifiers)
|
nil)
|
||||||
(println "available: points"))
|
|
||||||
#_(.exit js/process 0))
|
|
||||||
|
|
||||||
|
|
|
@ -107,26 +107,40 @@
|
||||||
children)))
|
children)))
|
||||||
|
|
||||||
(defn benchmark
|
(defn benchmark
|
||||||
[& {:keys [f warmup iterations name]
|
[& {:keys [run-fn chk-fn iterations name gc]
|
||||||
:or {iterations 10000}}]
|
:or {iterations 10000}}]
|
||||||
(let [end-mark (str name ":end")]
|
(let [end-mark (str name ":end")
|
||||||
|
blackhole (volatile! nil)]
|
||||||
(println "=> benchmarking:" name)
|
(println "=> benchmarking:" name)
|
||||||
(println "--> warming up:" iterations)
|
(when gc
|
||||||
(loop [i iterations]
|
(println "-> force gc: true"))
|
||||||
|
|
||||||
|
(println "--> warming up: " (* iterations 2))
|
||||||
|
(when (fn? gc) (gc))
|
||||||
|
(loop [i (* iterations 2)]
|
||||||
(when (pos? i)
|
(when (pos? i)
|
||||||
(f)
|
(vreset! blackhole (run-fn))
|
||||||
(recur (dec i))))
|
(recur (dec i))))
|
||||||
(println "--> benchmarking:" iterations)
|
(println "--> benchmarking:" iterations)
|
||||||
|
(when (fn? gc) (gc))
|
||||||
(js/performance.mark name)
|
(js/performance.mark name)
|
||||||
(loop [i iterations]
|
(loop [i iterations]
|
||||||
(when (pos? i)
|
(when (pos? i)
|
||||||
(f)
|
(vreset! blackhole (run-fn))
|
||||||
(recur (dec i))))
|
(recur (dec i))))
|
||||||
(js/performance.measure end-mark name)
|
(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)
|
(let [[result] (js/performance.getEntriesByName end-mark)
|
||||||
duration (mth/precision (.-duration ^js result) 4)
|
duration (mth/precision (.-duration ^js result) 4)
|
||||||
avg (mth/precision (/ duration iterations) 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.clearMarks name)
|
||||||
(js/performance.clearMeasures end-mark)
|
(js/performance.clearMeasures end-mark)
|
||||||
#js {:duration duration
|
#js {:duration duration
|
||||||
|
|
Loading…
Add table
Reference in a new issue