Created
December 4, 2014 13:42
-
-
Save krisajenkins/b280a52128c2e382d849 to your computer and use it in GitHub Desktop.
Quick Schema Benchmark
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 schemaspeed.core | |
(require [schema.core :as s])) | |
(def S {:name s/Str | |
:age s/Int | |
:things [s/Int]}) | |
(def xs | |
(doall (repeat 100000 | |
{:name "somename" | |
:age (rand-int 100) | |
:things (take 5 (repeatedly | |
#(rand-int 100)))}))) | |
;;; Q. Is there a difference between validating records individually, vs as a batch? | |
(time (do | |
(s/check [S] xs) | |
:ok)) | |
;=> "Elapsed time: 955.266 msecs" | |
(time (doseq [x xs] | |
(s/check S x) | |
:ok)) | |
;=> "Elapsed time: 3533.174 msecs" | |
;;; A. This quick benchmark says, yes. About 3-4x. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment