0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

More changes on bench core ns.

This commit is contained in:
Andrey Antukh 2016-04-11 17:32:40 +03:00
parent 4f0a74b1a3
commit 93a84d91e2
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -1,46 +1,48 @@
(ns bench.core (ns bench.core
(:require [kdtree :as k] (:require [kdtree.core :as k]
[cljs.pprint :refer (pprint)]
[cljs.nodejs :as node])) [cljs.nodejs :as node]))
(enable-console-print!) (enable-console-print!)
;; --- Helpers
(defn generate-points (defn generate-points
[n] ([n] (generate-points n 1))
(for [x (range 0 n) ([n step]
y (range 0 n)] (into-array
#js [x y])) (for [x (range 0 n step)
y (range 0 n step)]
#js [x y]))))
(defn bench-init-100 ;; --- Index Initialization Bechmark
[]
(js/console.time "init:100")
(let [points (into-array (generate-points 10))]
(k/create2d points)
(js/console.timeEnd "init:100")))
(defn bench-init-10000 (defn- bench-init-10000
[] []
(js/console.time "init:10000") (js/console.time "init:10000")
(let [points (into-array (generate-points 100))] (let [points (generate-points 1000 10)]
(println (count points))
(k/create2d points) (k/create2d points)
(js/console.timeEnd "init:10000"))) (js/console.timeEnd "init:10000")))
(defn bench-init-160000 (defn- bench-init-250000
[] []
(js/console.time "init:160000") (js/console.time "init:250000")
(let [points (into-array (generate-points 400))] (let [points (generate-points 5000 10)]
(println (count points))
(k/create2d points) (k/create2d points)
(js/console.timeEnd "init:160000"))) (js/console.timeEnd "init:250000")))
(defn bench-init (defn bench-init
[] []
(bench-init-100)
(bench-init-10000) (bench-init-10000)
(bench-init-160000)) (bench-init-250000))
(defn bench-knn-160000 ;; --- Nearest Search Benchmark
(defn- bench-knn-160000
[] []
(let [tree (-> (into-array (generate-points 400)) (let [tree (k/create2d (generate-points 4000 10))]
(k/create2d))]
(dotimes [i 100] (dotimes [i 100]
(js/console.time "knn:160000") (js/console.time "knn:160000")
(let [pt #js [(rand-int 400) (let [pt #js [(rand-int 400)
@ -48,10 +50,9 @@
(.nearest tree pt 2)) (.nearest tree pt 2))
(js/console.timeEnd "knn:160000")))) (js/console.timeEnd "knn:160000"))))
(defn bench-knn-360000 (defn- bench-knn-360000
[] []
(let [tree (-> (into-array (generate-points 600)) (let [tree (k/create2d (generate-points 6000 10))]
(k/create2d))]
(dotimes [i 100] (dotimes [i 100]
(js/console.time "knn:360000") (js/console.time "knn:360000")
(let [pt #js [(rand-int 600) (let [pt #js [(rand-int 600)
@ -64,17 +65,29 @@
(bench-knn-160000) (bench-knn-160000)
(bench-knn-360000)) (bench-knn-360000))
;; --- Accuracity tests
(defn test-accuracity
[]
(let [tree (k/create2d (generate-points 4000 20))]
(print "[1742 1419]")
(pprint (js->clj (.nearest tree #js [1742 1419] 6)))
(print "[1742 1420]")
(pprint (js->clj (.nearest tree #js [1742 1420] 6)))
))
(defn main (defn main
[& [type]] [& [type]]
(bench-init) (cond
(bench-knn)
#_(cond
(= type "init") (= type "init")
(bench-init) (bench-init)
(= type "knn") (= type "knn")
(bench-knn) (bench-knn)
(= type "test")
(test-accuracity)
:else :else
(println "not implemented"))) (println "not implemented")))