mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 20:46:11 +02:00
Minor changes on bench code.
This commit is contained in:
parent
808c964d3d
commit
3a448e33e4
1 changed files with 40 additions and 37 deletions
|
@ -1,5 +1,6 @@
|
||||||
(ns bench.core
|
(ns bench.core
|
||||||
(:require [kdtree :as k]))
|
(:require [kdtree :as k]
|
||||||
|
[cljs.nodejs :as node]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
@ -7,65 +8,67 @@
|
||||||
[n]
|
[n]
|
||||||
(for [x (range 0 n)
|
(for [x (range 0 n)
|
||||||
y (range 0 n)]
|
y (range 0 n)]
|
||||||
(k/point2d x y)))
|
#js [x y]))
|
||||||
|
|
||||||
(defn bench-init-100
|
(defn bench-init-100
|
||||||
[]
|
[]
|
||||||
|
(js/console.time "init:100")
|
||||||
(let [points (into-array (generate-points 10))]
|
(let [points (into-array (generate-points 10))]
|
||||||
(time
|
(k/create2d points)
|
||||||
(k/create2d points))))
|
(js/console.timeEnd "init:100")))
|
||||||
|
|
||||||
(defn bench-init-1000
|
|
||||||
[]
|
|
||||||
(let [points (into-array (generate-points 100))]
|
|
||||||
(time
|
|
||||||
(k/create2d points))))
|
|
||||||
|
|
||||||
(defn bench-init-10000
|
(defn bench-init-10000
|
||||||
[]
|
[]
|
||||||
(let [points (into-array (generate-points 1000))]
|
(js/console.time "init:10000")
|
||||||
(time
|
(let [points (into-array (generate-points 100))]
|
||||||
(k/create2d points))))
|
(k/create2d points)
|
||||||
|
(js/console.timeEnd "init:10000")))
|
||||||
|
|
||||||
|
(defn bench-init-160000
|
||||||
|
[]
|
||||||
|
(js/console.time "init:160000")
|
||||||
|
(let [points (into-array (generate-points 400))]
|
||||||
|
(k/create2d points)
|
||||||
|
(js/console.timeEnd "init:160000")))
|
||||||
|
|
||||||
(defn bench-init
|
(defn bench-init
|
||||||
[]
|
[]
|
||||||
(println "init:100")
|
|
||||||
(bench-init-100)
|
(bench-init-100)
|
||||||
(println "init:1000")
|
(bench-init-10000)
|
||||||
(bench-init-1000)
|
(bench-init-160000))
|
||||||
(println "init:10000")
|
|
||||||
(bench-init-10000))
|
|
||||||
|
|
||||||
(defn bench-knn-100000-2
|
(defn bench-knn-160000
|
||||||
[]
|
[]
|
||||||
(let [tree (-> (into-array (generate-points 10000))
|
(let [tree (-> (into-array (generate-points 400))
|
||||||
(k/create2d points))
|
(k/create2d))]
|
||||||
pt (k/point2d (rand-int 10000)
|
|
||||||
(rand-int 10000))]
|
|
||||||
|
|
||||||
(dotimes [i 100]
|
(dotimes [i 100]
|
||||||
(time
|
(js/console.time "knn:160000")
|
||||||
(.nearest tree pt 2)))))
|
(let [pt #js [(rand-int 400)
|
||||||
|
(rand-int 400)]]
|
||||||
|
(.nearest tree pt 2))
|
||||||
|
(js/console.timeEnd "knn:160000"))))
|
||||||
|
|
||||||
(defn bench-knn-10000-2
|
(defn bench-knn-360000
|
||||||
[]
|
[]
|
||||||
(let [tree (-> (into-array (generate-points 1000))
|
(let [tree (-> (into-array (generate-points 600))
|
||||||
(k/create2d points))
|
(k/create2d))]
|
||||||
pt (k/point2d (rand-int 1000)
|
|
||||||
(rand-int 1000))]
|
|
||||||
|
|
||||||
(dotimes [i 100]
|
(dotimes [i 100]
|
||||||
(time
|
(js/console.time "knn:360000")
|
||||||
(.nearest tree pt 2)))))
|
(let [pt #js [(rand-int 600)
|
||||||
|
(rand-int 600)]]
|
||||||
|
(.nearest tree pt 2))
|
||||||
|
(js/console.timeEnd "knn:360000"))))
|
||||||
|
|
||||||
(defn bench-knn
|
(defn bench-knn
|
||||||
[]
|
[]
|
||||||
(println "knn:10000:2")
|
(bench-knn-160000)
|
||||||
(bench-knn-10000-2))
|
(bench-knn-360000))
|
||||||
|
|
||||||
(defn main
|
(defn main
|
||||||
[& [type]]
|
[& [type]]
|
||||||
(cond
|
(bench-init)
|
||||||
|
(bench-knn)
|
||||||
|
#_(cond
|
||||||
(= type "init")
|
(= type "init")
|
||||||
(bench-init)
|
(bench-init)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue