Skip to content

Commit

Permalink
fixed arange, hash-arr, refactor resolve-clause
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jul 30, 2015
1 parent 331773b commit 3b47f92
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 145 deletions.
60 changes: 35 additions & 25 deletions dev/q3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

(comment

(defn rand-entity []
{:name (rand-nth ["ivan" "oleg" "petr" "igor"])
:age (rand-int 10)})

(defn random-man []
{:name (rand-nth ["Ivan" "Petr" "Sergei" "Oleg" "Yuri" "Dmitry" "Fedor" "Denis"])
:last-name (rand-nth ["Ivanov" "Petrov" "Sidorov" "Kovalev" "Kuznetsov" "Voronoi"])
:sex (rand-nth [:male :female])
:age (rand-int 10)
:salary (rand-int 100000)})

(perf/minibench "q coll"
(q/q '[:find ?a
:in $1 $2 ?n
Expand All @@ -18,50 +29,48 @@
(require '[datascript.query-v3 :as q] :reload)

(binding [datascript.perf/debug? true]
(let [entities (repeatedly 5 rand-entity)
;; _ (println entities)
(let [entities [{:name "Ivan" :age 1}
{:name "Ivan" :age 2}
{:name "Oleg" :age 1}
{:name "Oleg" :age 2}]
db (d/db-with (d/empty-db) entities)
result (q/q '[:find ?e ?n ?e2 ?a
result (q/q '[:find ?e ?a ?e2 ?a2
:in $
:where [?e :name ?n]
#_[?e2 :name ?n]
[?e2 :age ?a]]
:where [?e :name "Ivan"]
[?e2 :name "Oleg"]
[?e :age ?a]
[?e2 :age ?a2]
[?e :age ?a2]]
db)]
#_[entities result]
result))


(defn rand-entity []
{:name (rand-nth ["ivan" "oleg" "petr" "igor"])
:age (rand-int 10)})

(defn random-man []
{:name (rand-nth ["Ivan" "Petr" "Sergei" "Oleg" "Yuri" "Dmitry" "Fedor" "Denis"])
:last-name (rand-nth ["Ivanov" "Petrov" "Sidorov" "Kovalev" "Kuznetsov" "Voronoi"])
:sex (rand-nth [:male :female])
:age (rand-int 10)
:salary (rand-int 100000)})

(require '[datascript.query-v3 :as q] :reload-all)

(defn bench [name q & args]
(println "\n---\n")
(perf/minibench (str "OLD " name) (apply d/q q args))
(perf/minibench (str "NEW " name) (apply q/q q args))
nil)
(let [old (perf/minibench (str "OLD " name) (apply d/q q args))
new (perf/minibench (str "NEW " name) (apply q/q q args))]
(= old new)))

(defonce db (d/db-with (d/empty-db) (repeatedly 100000 random-man)))
(def db (d/db-with (d/empty-db) (repeatedly 1000 random-man)))

(require 'datascript.perf :reload-all)
(require '[datascript.query-v3 :as q] :reload)

(bench "q2 const"
'[:find ?e ?a ?s ?w ?ln
'[:find ?e ?e2 ?a ?a2
:where [?e :name "Ivan"]
[?e2 :name "Oleg"]
[?e :age ?a]
[?e :sex ?s]
[?e :salary ?w]
[?e :last-name ?ln]]
[?e2 :age ?a2]
[?e :age ?a2]

;; [?e :sex ?s]
;; [?e :salary ?w]
;; [?e :last-name ?ln]
]
db)

(bench "q2 const in"
Expand All @@ -70,4 +79,5 @@
:where [?e :name "Ivan"]
[?e :age ?n]]
db 1)

)
Loading

0 comments on commit 3b47f92

Please sign in to comment.