Skip to content

Commit

Permalink
last minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jun 28, 2015
1 parent 67a0b80 commit d174467
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
55 changes: 39 additions & 16 deletions bench/bench
Original file line number Diff line number Diff line change
Expand Up @@ -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) (<test-name>|all) (<tag>|<revision>)"
"USAGE: ./bench [-c | -f] (jvm|js) (<bench-name>|all) (<tag>|<revision>)"

(require
'[clojure.edn :as edn]
Expand Down Expand Up @@ -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"))
Expand All @@ -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"
Expand Down Expand Up @@ -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)
15 changes: 8 additions & 7 deletions bench/src/datascript/bench.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)))
Expand Down
12 changes: 6 additions & 6 deletions src/datascript/btset.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))))))
Expand Down Expand Up @@ -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)))))))))

Expand Down
8 changes: 6 additions & 2 deletions src/datascript/shim.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit d174467

Please sign in to comment.