Skip to content

Instantly share code, notes, and snippets.

@prayerslayer
Last active September 28, 2015 13:23
Show Gist options
  • Save prayerslayer/1664adce9d43639f6762 to your computer and use it in GitHub Desktop.
Save prayerslayer/1664adce9d43639f6762 to your computer and use it in GitHub Desktop.
Tests JSON encoding performance of different clojure libs
content length
5073891
cheshire
"Elapsed time: 103.332902 msecs"
clj-json
"Elapsed time: 79.033905 msecs"
core.json
"Elapsed time: 638.59961 msecs"
(use '[leiningen.exec :only (deps)])
(deps '[[cheshire "5.5.0"]
[clj-json "0.5.3"]
[org.clojure/data.json "0.2.6"]])
(ns json-speed-test
(:require [clojure.data.json :as core]
[cheshire.core :as cheshire]
[clj-json [core :as cljjson]]))
(defn rand-string
[& args]
(->> (range (or (first args)
(rand-int 50)))
(map (fn [x] (+ 65 (rand-int 26))))
(map #(char %))
(map #(Character/toString %))
(apply str)))
(let [payload (->> (range 15000)
(map #(assoc {} :id (str "app-" %)
:name (rand-string 20)
:team-id (rand-string 10)
:description (rand-string 250)))
(doall))]
(println "content length")
(println (count (cljjson/generate-string payload)))
(println "cheshire")
(time (cheshire/generate-string payload))
(println "clj-json")
(time (cljjson/generate-string payload))
(println "core.json")
(time (core/write-str payload)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment