Skip to content

Instantly share code, notes, and snippets.

@boronine
Created May 15, 2015 08:23
Show Gist options
  • Save boronine/82b9ffa14ba86282afd5 to your computer and use it in GitHub Desktop.
Save boronine/82b9ffa14ba86282afd5 to your computer and use it in GitHub Desktop.
EDN vs JSON parsing speed
; lein new mies-node edn-vs-json
; vim edn-vs-json/src/edn_vs_json/core.cljs
; lein cljs build once
; node run.js
(ns edn-vs-json.core
(:require
[cljs.nodejs :as nodejs]
[cljs.reader :as reader]
[clojure.string :as string]))
(nodejs/enable-util-print!)
(def sample-json "{\"a\": 1283991.1232, \"b\": [true, false, null], \"c\": 0}")
(def sample-edn "{:a 1283991.1232 :b [true false nil] :c 0}")
(def big-json (str "[" (string/join "," (repeat 50000 sample-json)) "]"))
(def big-edn (str "[" (string/join " " (repeat 50000 sample-edn)) "]"))
(defn -main []
(.log js/console "json size:" (count big-json))
(.time js/console "json-parse")
(.parse js/JSON big-json)
(.timeEnd js/console "json-parse")
(.log js/console "edn size:" (count big-edn))
(.time js/console "edn-parse")
(reader/read-string big-edn)
(.timeEnd js/console "edn-parse"))
(set! *main-cli-fn* -main)
@boronine
Copy link
Author

Results:

json size: 2700001
json-parse: 43ms
edn size: 2150001
edn-parse: 3081ms

JSON 71x times faster.

@novakboskov
Copy link

Is it same to use cljs.reader/read-string and clojure.edn/read-string according to this?

@middlesphere
Copy link

edn purpose to convey values and it is not optimised for speed.
For speed use Transit format, which is EDN optimised for speed.
https://github.com/cognitect/transit-format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment