Skip to content

Instantly share code, notes, and snippets.

@Jaretbinford
Created September 19, 2016 19:30
Show Gist options
  • Save Jaretbinford/78702cae1b1dcd1063bbafdbd0c543a2 to your computer and use it in GitHub Desktop.
Save Jaretbinford/78702cae1b1dcd1063bbafdbd0c543a2 to your computer and use it in GitHub Desktop.
in-memory transaction tests
(ns inmemperformance.core
(require [datomic.api :as d]
[clojure.java.io :as io]))
(def db-uri "datomic:mem://memory")
(d/delete-database db-uri)
(d/create-database db-uri)
(def conn (d/connect db-uri))
(def schema [{:db/id (d/tempid :db.part/db)
:db/ident :memory/content
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "putting 10000 writes against"
:db.install/_attribute :db.part/db}])
@(d/transact conn schema)
;;Characters
(def definedchars
(map char (concat
(range 48 58)
(range 66 91)
(range 97 123))))
;;rand-nth char to use
(defn random-char []
(rand-nth definedchars))
;;Make some random input
(defn random-input [length]
(apply str(take length(repeatedly random-char))))
(defn populate [length]
{:db/id (d/tempid :db.part/user)
:memory/content (random-input length)}
)
(time (dotimes [_ 10000]
@(d/transact conn [(populate 6)])
))
;;"Elapsed time: 11480.636872 msecs"
;;"Elapsed time: 7542.200299 msecs"
;;Using a fixed string
(time (dotimes [_ 10000]
@(d/transact conn [{:db/id (d/tempid :db.part/user)
:memory/content "foo"}])
))
;;"Elapsed time: 6232.295513 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment