diff --git a/bench/bench b/bench/bench index e99be761..882a33ce 100755 --- a/bench/bench +++ b/bench/bench @@ -2,7 +2,7 @@ exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.7.0-RC2/clojure-1.7.0-RC2.jar" clojure.main "$0" "$@" ] -"USAGE: ./bench [-c] (jvm|js) (|all) (|)" +"USAGE: ./bench [-c | -f] (jvm|js) (|all) (|)" (require '[clojure.edn :as edn] @@ -53,19 +53,40 @@ exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.7.0-RC2/clojure-1.7.0- (str commit-count "/" (subs sha1 0 7) "/" (str/replace descr #"-g.+" "")))) -(def clean? (#{"-c" "-clean" "--clean"} (first *command-line-args*))) -(let [[p b r] (if clean? - (next *command-line-args*) - *command-line-args*)] - (def project (get {"jvm" "datascript-jvm" - "js" "datascript-v8" - "datomic" "datomic-mem"} - (or p "jvm"))) - (def datomic? (= "datomic-mem" project)) - (def bench (or b "all")) - (def rfrnc (if datomic? - (or r "0.9.5173") - r))) +(def opts + (loop [opts {:clean false + :fast false + :project "jvm" + :bench "all" + :ref nil} + args *command-line-args*] + (if-let [arg (first args)] + (cond + (#{"-c" "-clean" "--clean"} arg) + (recur (assoc opts :clean true) (next args)) + (#{"-f" "-fast" "--fast"} arg) + (recur (assoc opts :fast true) (next args)) + (#{"jvm" "js" "datomic"} arg) + (recur (assoc opts :project arg) (next args)) + (#{"db_with" "init_db" "queries" "rules" "btset"} arg) + (recur (assoc opts :bench arg) (next args)) + (re-matches #"[0-9.\-]+" arg) + (recur (assoc opts :ref arg) (next args)) + :else + (throw (ex-info "Unknown option: " {:arg arg :args *command-line-args*}))) + opts))) + +(def clean? (:clean opts)) +(def skip-build? (:fast opts)) +(def project (get {"jvm" "datascript-jvm" + "js" "datascript-v8" + "datomic" "datomic-mem"} + (:project opts))) +(def datomic? (= "datomic-mem" project)) +(def bench (:bench opts)) +(def rfrnc (if datomic? + (or (:ref opts) "0.9.5173") + (:ref opts))) (def dir (if rfrnc "." "..")) (def rdir (if rfrnc "." "./bench")) @@ -89,7 +110,8 @@ exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.7.0-RC2/clojure-1.7.0- "datascript-v8" (do - (run "lein" "cljsbuild" "once" "advanced") + (when-not skip-build? + (run "lein" "cljsbuild" "once" "advanced")) (run "node" (str rdir "/run_v8.js") bench (str dir "/target/datascript.js"))) "datomic-mem" @@ -126,6 +148,7 @@ exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.7.0-RC2/clojure-1.7.0- (when clean? (run "lein" "clean")) (let [out (run-bench)] - (merge-results out))) + (when-not skip-build? + (merge-results out)))) (System/exit 0) diff --git a/bench/src/datascript/bench.cljc b/bench/src/datascript/bench.cljc index 9cc10518..38661be3 100644 --- a/bench/src/datascript/bench.cljc +++ b/bench/src/datascript/bench.cljc @@ -112,8 +112,8 @@ (follows ?t ?y)]])))) (defn ^:export bench-btset [] - (doseq [[tn target] [;; ["sorted-set" (sorted-set)] - ;; ["vec" []] + (doseq [[tn target] [["sorted-set" (sorted-set)] + ["vector" []] ["btset" (btset/btset)]] ;; distinct? [true false] size [100 500 20000] @@ -124,11 +124,12 @@ set (into target range)]] (perf/bench {:target tn :test "set-conj" :size size} (into target range)) - (perf/bench {:target tn :test "set-disj" :size size} - (reduce disj set shuffled-range)) - (perf/bench {:target tn :test "set-lookup" :size size} - (doseq [i shuffled-range] - (contains? set i))) + (when (re-find #"set" tn) + (perf/bench {:target tn :test "set-disj" :size size} + (reduce disj set shuffled-range)) + (perf/bench {:target tn :test "set-lookup" :size size} + (doseq [i shuffled-range] + (contains? set i)))) (perf/bench {:target tn :test "set-iterate" :size size} (doseq [x set] (+ 1 x))) diff --git a/src/datascript/btset.cljc b/src/datascript/btset.cljc index bfa2ec98..d6ddf94c 100644 --- a/src/datascript/btset.cljc +++ b/src/datascript/btset.cljc @@ -36,11 +36,11 @@ [datascript.shim :as shim]) #?(:clj (:import [java.util Arrays]))) -(def ^:const min-len #?(:clj 16 :cljs 64)) -(def ^:const max-len #?(:clj 31 :cljs 128)) +(def ^:const min-len 16) +(def ^:const max-len 32) (def ^:const avg-len (shim/half (+ max-len min-len))) (def ^:const level-shift (->> (range 31 -1 -1) - (filter #(bit-test max-len %)) + (filter #(bit-test (dec max-len) %)) first inc)) (def ^:const path-mask (dec (bit-shift-left 1 level-shift))) @@ -154,8 +154,8 @@ (cond (== i len) true - (not (== 0 (cmp (shim/aget a1 (+ i a1-from)) - (shim/aget a2 (+ i a2-from))))) + (shim/not== 0 (cmp (shim/aget a1 (+ i a1-from)) + (shim/aget a2 (+ i a2-from)))) false :else (recur (inc i))))))) @@ -821,7 +821,7 @@ (recur (inc left) keys (inc idx) new-acc) new-acc) (let [new-left (next-path set left)] - (if (and (not= -1 new-left) (< new-left right)) + (if (and (shim/not== -1 new-left) (< new-left right)) (recur new-left (keys-for set new-left) (path-get new-left 0) new-acc) new-acc))))))))) diff --git a/src/datascript/shim.cljc b/src/datascript/shim.cljc index b1a32d37..04e33cc9 100644 --- a/src/datascript/shim.cljc +++ b/src/datascript/shim.cljc @@ -95,5 +95,9 @@ (def neg-number? (every-pred number? neg?)) #?(:clj -(defmacro half [x] - `(unsigned-bit-shift-right ~x 1))) + (defmacro half [x] + `(unsigned-bit-shift-right ~x 1))) + +#?(:clj + (defmacro not== [x y] + `(not (== ~x ~y))))