mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 06:31:37 +02:00
📎 Update frontend bench namespace
This commit is contained in:
parent
fc4e755f2b
commit
04243be4a5
1 changed files with 9 additions and 26 deletions
|
@ -1,6 +1,7 @@
|
||||||
(ns bench
|
(ns bench
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[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.geom.shapes.rect :as gsr]
|
||||||
[app.common.perf :as perf]
|
[app.common.perf :as perf]
|
||||||
|
@ -10,39 +11,21 @@
|
||||||
(def points
|
(def points
|
||||||
(gen/sample (s/gen ::gpt/point) 20))
|
(gen/sample (s/gen ::gpt/point) 20))
|
||||||
|
|
||||||
(defn points->rect
|
|
||||||
[points]
|
|
||||||
(when-let [points (seq points)]
|
|
||||||
(loop [minx ##Inf
|
|
||||||
miny ##Inf
|
|
||||||
maxx ##-Inf
|
|
||||||
maxy ##-Inf
|
|
||||||
pts points]
|
|
||||||
(if-let [pt ^boolean (first pts)]
|
|
||||||
(let [x (d/get-prop pt :x)
|
|
||||||
y (d/get-prop pt :y)]
|
|
||||||
(recur (min minx x)
|
|
||||||
(min miny y)
|
|
||||||
(max maxx x)
|
|
||||||
(max maxy y)
|
|
||||||
(rest pts)))
|
|
||||||
(when (d/num? minx miny maxx maxy)
|
|
||||||
(gsr/make-rect minx miny (- maxx minx) (- maxy miny)))))))
|
|
||||||
|
|
||||||
(defn bench-points
|
(defn bench-points
|
||||||
[]
|
[]
|
||||||
|
#_(perf/benchmark
|
||||||
|
:f #(gpt/center-points-old points)
|
||||||
|
:samples 20
|
||||||
|
:max-iterations 500000
|
||||||
|
:name "base")
|
||||||
(perf/benchmark
|
(perf/benchmark
|
||||||
:f #(gsr/points->rect points)
|
:f #(gpt/center-points points)
|
||||||
:name "base")
|
:max-iterations 500000
|
||||||
(perf/benchmark
|
:samples 20
|
||||||
:f #(points->rect points)
|
|
||||||
:name "optimized"))
|
:name "optimized"))
|
||||||
|
|
||||||
|
|
||||||
(defn main
|
(defn main
|
||||||
[& [name]]
|
[& [name]]
|
||||||
(case name
|
(case name
|
||||||
"points" (bench-points)
|
"points" (bench-points)
|
||||||
(println "available: points")))
|
(println "available: points")))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue