Created
September 19, 2016 19:30
-
-
Save Jaretbinford/78702cae1b1dcd1063bbafdbd0c543a2 to your computer and use it in GitHub Desktop.
in-memory transaction tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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