0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00
penpot/frontend/dev/bench/core.cljs

113 lines
2.3 KiB
Text
Raw Normal View History

2016-04-07 14:51:40 -05:00
(ns bench.core
2016-04-11 09:32:40 -05:00
(:require [kdtree.core :as k]
[intervaltree.core :as it]
2016-04-11 09:32:40 -05:00
[cljs.pprint :refer (pprint)]
2016-04-09 12:32:15 -05:00
[cljs.nodejs :as node]))
2016-04-07 14:51:40 -05:00
(enable-console-print!)
2016-04-11 09:32:40 -05:00
;; --- Index Initialization Bechmark
2016-04-07 14:51:40 -05:00
2016-04-11 09:32:40 -05:00
(defn- bench-init-10000
2016-04-07 14:51:40 -05:00
[]
(println "1000x1000,10 -> 10000 points")
(time
(k/generate 1000 1000 10 10)))
2016-04-07 14:51:40 -05:00
2016-04-11 09:32:40 -05:00
(defn- bench-init-250000
2016-04-07 14:51:40 -05:00
[]
(time
(k/generate 5000 5000 10 10)))
2016-04-07 14:51:40 -05:00
(defn bench-init
[]
2016-04-09 12:32:15 -05:00
(bench-init-10000)
(bench-init-10000)
(bench-init-250000)
(bench-init-250000)
(bench-init-10000)
(bench-init-10000)
(bench-init-250000)
2016-04-11 09:32:40 -05:00
(bench-init-250000))
;; --- Nearest Search Benchmark
2016-04-07 14:51:40 -05:00
2016-04-11 09:32:40 -05:00
(defn- bench-knn-160000
2016-04-07 14:51:40 -05:00
[]
(let [tree (k/create)]
(k/setup tree 4000 4000 10 10)
(println "KNN Search (160000 points) 1000 times")
(time
(dotimes [i 1000]
(let [pt #js [(rand-int 400)
(rand-int 400)]]
(k/nearest tree pt 2))))))
2016-04-07 14:51:40 -05:00
2016-04-11 09:32:40 -05:00
(defn- bench-knn-360000
2016-04-07 14:51:40 -05:00
[]
(let [tree (k/create)]
(k/initialize tree 6000 6000 10 10)
(println "KNN Search (360000 points) 1000 times")
(time
(dotimes [i 1000]
(let [pt #js [(rand-int 600)
(rand-int 600)]]
(k/nearest tree pt 2))))))
2016-04-07 14:51:40 -05:00
(defn bench-knn
[]
2016-04-09 12:32:15 -05:00
(bench-knn-160000)
(bench-knn-360000))
2016-04-07 14:51:40 -05:00
2016-04-11 09:32:40 -05:00
;; --- Accuracity tests
(defn test-accuracity
[]
(let [tree (k/create)]
(k/setup tree 4000 4000 20 20)
2016-04-11 09:32:40 -05:00
(print "[1742 1419]")
(pprint (js->clj (k/nearest tree #js [1742 1419] 6)))
2016-04-11 09:32:40 -05:00
(print "[1742 1420]")
(pprint (js->clj (k/nearest tree #js [1742 1420] 6)))
2016-04-11 09:32:40 -05:00
))
(defn test-interval
[]
(let [tree (it/create)]
(it/add tree #js [1 5])
(it/add tree #js [5 7])
(it/add tree #js [-4 -1])
(it/add tree #js [-10 -3])
(it/add tree #js [-20 -10])
(it/add tree #js [20 30])
(it/add tree #js [3 9])
(it/add tree #js [100 200])
(it/add tree #js [1000 2000])
(it/add tree #js [6 9])
(js/console.dir tree #js {"depth" nil})
(js/console.log "contains", 4, (it/contains tree 4))
(js/console.log "contains", 0, (it/contains tree 0))
))
2016-04-07 14:51:40 -05:00
(defn main
[& [type]]
2016-04-11 09:32:40 -05:00
(cond
(= type "kd-init")
2016-04-07 14:51:40 -05:00
(bench-init)
(= type "kd-search")
2016-04-07 14:51:40 -05:00
(bench-knn)
(= type "kd-test")
2016-04-11 09:32:40 -05:00
(test-accuracity)
(= type "interval")
(test-interval)
2016-04-07 14:51:40 -05:00
:else
(println "not implemented")))
(set! *main-cli-fn* main)