Created
May 15, 2015 08:23
-
-
Save boronine/82b9ffa14ba86282afd5 to your computer and use it in GitHub Desktop.
EDN vs JSON parsing speed
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
; 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) |
Is it same to use cljs.reader/read-string
and clojure.edn/read-string
according to this?
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
Results:
json size: 2700001
json-parse: 43ms
edn size: 2150001
edn-parse: 3081ms
JSON 71x times faster.