Skip to content

Instantly share code, notes, and snippets.

@krisajenkins
Created December 4, 2014 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisajenkins/b280a52128c2e382d849 to your computer and use it in GitHub Desktop.
Save krisajenkins/b280a52128c2e382d849 to your computer and use it in GitHub Desktop.
Quick Schema Benchmark
(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