diff --git a/dev/bench/core.cljs b/dev/bench/core.cljs new file mode 100644 index 000000000..a4411cc0c --- /dev/null +++ b/dev/bench/core.cljs @@ -0,0 +1,78 @@ +(ns bench.core + (:require [kdtree :as k])) + +(enable-console-print!) + +(defn generate-points + [n] + (for [x (range 0 n) + y (range 0 n)] + (k/point2d x y))) + +(defn bench-init-100 + [] + (let [points (into-array (generate-points 10))] + (time + (k/create2d points)))) + +(defn bench-init-1000 + [] + (let [points (into-array (generate-points 100))] + (time + (k/create2d points)))) + +(defn bench-init-10000 + [] + (let [points (into-array (generate-points 1000))] + (time + (k/create2d points)))) + +(defn bench-init + [] + (println "init:100") + (bench-init-100) + (println "init:1000") + (bench-init-1000) + (println "init:10000") + (bench-init-10000)) + +(defn bench-knn-100000-2 + [] + (let [tree (-> (into-array (generate-points 10000)) + (k/create2d points)) + pt (k/point2d (rand-int 10000) + (rand-int 10000))] + + (dotimes [i 100] + (time + (.nearest tree pt 2))))) + +(defn bench-knn-10000-2 + [] + (let [tree (-> (into-array (generate-points 1000)) + (k/create2d points)) + pt (k/point2d (rand-int 1000) + (rand-int 1000))] + + (dotimes [i 100] + (time + (.nearest tree pt 2))))) + +(defn bench-knn + [] + (println "knn:10000:2") + (bench-knn-10000-2)) + +(defn main + [& [type]] + (cond + (= type "init") + (bench-init) + + (= type "knn") + (bench-knn) + + :else + (println "not implemented"))) + +(set! *main-cli-fn* main) diff --git a/project.clj b/project.clj index 7b976a03a..28cc3c441 100644 --- a/project.clj +++ b/project.clj @@ -4,6 +4,11 @@ :license {:name "MPL 2.0" :url "https://www.mozilla.org/en-US/MPL/2.0/"} :jvm-opts ["-Dclojure.compiler.direct-linking=true"] + :source-paths ["src" "vendor"] + :test-paths ["test"] + + :profiles {:dev {:source-paths ["dev"]}} + :dependencies [[org.clojure/clojure "1.8.0" :scope "provided"] [org.clojure/clojurescript "1.8.40" :scope "provided"] [figwheel-sidecar "0.5.2" :scope "test"] diff --git a/scripts/build b/scripts/build deleted file mode 100755 index 0b894a2fb..000000000 --- a/scripts/build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -lein trampoline run -m clojure.main scripts/build.clj diff --git a/scripts/build-bench b/scripts/build-bench new file mode 100755 index 000000000..e3c4da20f --- /dev/null +++ b/scripts/build-bench @@ -0,0 +1,2 @@ +#!/bin/sh +lein trampoline run -m clojure.main scripts/build-bench.clj diff --git a/scripts/build-bench.clj b/scripts/build-bench.clj new file mode 100644 index 000000000..e76ed965a --- /dev/null +++ b/scripts/build-bench.clj @@ -0,0 +1,13 @@ +(require '[cljs.build.api :as b]) + +(b/build + (b/inputs "vendor" "dev") + {:main 'bench.core + :output-to "out/bench.js" + :output-dir "out" + :parallel-build false + :optimizations :simple + :language-in :ecmascript5 + :language-out :ecmascript5 + :target :nodejs + :verbose true}) diff --git a/scripts/build-tests b/scripts/build-tests new file mode 100755 index 000000000..ab086e388 --- /dev/null +++ b/scripts/build-tests @@ -0,0 +1,2 @@ +#!/bin/sh +lein trampoline run -m clojure.main scripts/build-tests.clj diff --git a/scripts/build.clj b/scripts/build-tests.clj similarity index 94% rename from scripts/build.clj rename to scripts/build-tests.clj index 64146298f..b47a83d9c 100644 --- a/scripts/build.clj +++ b/scripts/build-tests.clj @@ -8,7 +8,7 @@ (let [start (System/nanoTime)] (b/build - (b/inputs "src" "test") + (b/inputs "src" "vendor" "test") {:main 'uxbox.test-runner :output-to "out/tests.js" :output-dir "out" diff --git a/scripts/dist.clj b/scripts/dist.clj index 0456001d0..22492f61b 100644 --- a/scripts/dist.clj +++ b/scripts/dist.clj @@ -8,7 +8,7 @@ (let [start (System/nanoTime)] (b/build - (b/inputs "src") + (b/inputs "src" "vendor") {:main 'uxbox.core :parallel-build false :warnings {:ns-var-clash false} diff --git a/scripts/figwheel.clj b/scripts/figwheel.clj index 4ac2401e0..6575e7621 100644 --- a/scripts/figwheel.clj +++ b/scripts/figwheel.clj @@ -11,13 +11,15 @@ :all-builds [{:id "dev" :figwheel {:on-jsload "uxbox.ui/init"} - :source-paths ["src"] + :source-paths ["src" "vendor"] :compiler {:main 'uxbox.core :asset-path "js" :parallel-build false :optimizations :none + ;; :closure-defines {"uxbox.repo.core.url" + ;; "https://test.uxbox.io/api"} :closure-defines {"uxbox.repo.core.url" - "https://test.uxbox.io/api"} + "http://localhost:6060/api"} :warnings {:ns-var-clash false} :pretty-print true :language-in :ecmascript5 diff --git a/scripts/watch-bench b/scripts/watch-bench new file mode 100755 index 000000000..663fcd703 --- /dev/null +++ b/scripts/watch-bench @@ -0,0 +1,2 @@ +#!/bin/sh +lein trampoline run -m clojure.main scripts/watch-bench.clj diff --git a/scripts/watch-bench.clj b/scripts/watch-bench.clj new file mode 100644 index 000000000..31c1ca1dc --- /dev/null +++ b/scripts/watch-bench.clj @@ -0,0 +1,14 @@ +(require '[cljs.build.api :as b]) + +(b/watch + (b/inputs "vendor" "dev") + {:main 'bench.core + :output-to "out/bench.js" + :output-dir "out" + :parallel-build false + :optimizations :simple + :pretty-print true + :target :nodejs + :language-in :ecmascript6 + :language-out :ecmascript5 + :verbose true}) diff --git a/scripts/watch b/scripts/watch-tests similarity index 100% rename from scripts/watch rename to scripts/watch-tests diff --git a/scripts/watch.clj b/scripts/watch-tests.clj similarity index 91% rename from scripts/watch.clj rename to scripts/watch-tests.clj index c073cc75b..63a89bb7e 100644 --- a/scripts/watch.clj +++ b/scripts/watch-tests.clj @@ -4,7 +4,7 @@ (alter-var-root #'cljs.tagged-literals/*cljs-data-readers* assoc 'ux/tr (fn [v] `(uxbox.locales/tr ~v))) -(b/watch (b/inputs "src" "test") +(b/watch (b/inputs "src" "vendor" "test") {:main 'uxbox.test-runner :output-to "out/tests.js" :output-dir "out"