mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 14:48:28 +02:00
📎 Add bench namespace to fronend/dev
This commit is contained in:
parent
89a19dec5b
commit
380cba3a72
2 changed files with 50 additions and 2 deletions
48
frontend/dev/bench.cljs
Normal file
48
frontend/dev/bench.cljs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
(ns bench
|
||||||
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.geom.shapes.rect :as gsr]
|
||||||
|
[app.common.perf :as perf]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.test.check.generators :as gen]))
|
||||||
|
|
||||||
|
(def points
|
||||||
|
(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
|
||||||
|
[]
|
||||||
|
(perf/benchmark
|
||||||
|
:f #(gsr/points->rect points)
|
||||||
|
:name "base")
|
||||||
|
(perf/benchmark
|
||||||
|
:f #(points->rect points)
|
||||||
|
:name "optimized"))
|
||||||
|
|
||||||
|
|
||||||
|
(defn main
|
||||||
|
[& [name]]
|
||||||
|
(case name
|
||||||
|
"points" (bench-points)
|
||||||
|
(println "available: points")))
|
||||||
|
|
||||||
|
|
|
@ -69,10 +69,10 @@
|
||||||
{:target :node-script
|
{:target :node-script
|
||||||
:output-to "target/bench.js"
|
:output-to "target/bench.js"
|
||||||
:output-dir "target/bench/"
|
:output-dir "target/bench/"
|
||||||
:main cljs.user/main
|
:main bench/main
|
||||||
|
|
||||||
:compiler-options
|
:compiler-options
|
||||||
{:output-feature-set :es8
|
{:output-feature-set :es2020
|
||||||
:output-wrapper false
|
:output-wrapper false
|
||||||
:warnings {:fn-deprecated false}}
|
:warnings {:fn-deprecated false}}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue