-
-
Save bonifaido/1988623 to your computer and use it in GitHub Desktop.
This file contains 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 json-bench.core | |
(:require [cheshire.core :as cheshire]) | |
(:require [clojure.data.json :as json]) | |
(:require [clj-json.core :as clj-json])) | |
(defn nano-time [] | |
(System/nanoTime)) | |
(defn timed [task] | |
(let [t-start (nano-time) | |
res (task) | |
t-end (nano-time)] | |
(double (/ (- t-end t-start) 1000000000)))) | |
(def record | |
{:keyword :foo | |
:string "Lorem ipsum dolor sit amet, consectetur adipiscing elit." | |
:integer 3 | |
:long 52001110638799097 | |
:double 1.23 | |
:boolean true | |
:nil nil | |
:map {"hi" 9 "low" 0} | |
:vector ["a" "b" "c"] | |
:list '(1 2 3)}) | |
(def roundtrips 100000) | |
(defn bench [name f] | |
(print name " ") | |
(flush) | |
(printf "%.2f\n" (timed #(dotimes [_ roundtrips] (f record)))) | |
(flush)) | |
(defn -main [& args] | |
(println "Clojure version: " | |
(str (:major *clojure-version*) "." | |
(:minor *clojure-version*) "." | |
(:incremental *clojure-version*))) | |
(println "Num roundtrips: " roundtrips) | |
(println) | |
(dotimes [i 2] | |
(println "Trail: " (inc i)) | |
(bench "cheshire " | |
#(cheshire/parse-string (cheshire/generate-string %))) | |
(bench "clojure.data.json " | |
#(json/read-json (json/json-str %))) | |
(bench "clj-json " | |
#(clj-json/parse-string (clj-json/generate-string %))) | |
(bench "reader/printer (*print-dup* false) " | |
#(binding [*print-dup* false] (read-string (pr-str %)))) | |
(bench "reader/printer (*print-dup* true) " | |
#(binding [*print-dup* true] (read-string (pr-str %)))) | |
(println))) |
This file contains 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
Clojure version: 1.3.0 | |
Num roundtrips: 100000 | |
Trail: 1 | |
cheshire 3.21 | |
clojure.data.json 6.93 | |
clj-json 2.72 | |
reader/printer (*print-dup* false) 11.34 | |
reader/printer (*print-dup* true) 14.28 | |
Trail: 2 | |
cheshire 2.45 | |
clojure.data.json 6.52 | |
clj-json 1.99 | |
reader/printer (*print-dup* false) 9.10 | |
reader/printer (*print-dup* true) 13.09 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment