The clojure.contrib.base64 discussion has inspired me (sorry!) to write this.. I would very much like to see a faster JSON parser be in contrib. clj-json can beat clojure.data.json by up to a factor of 140x when reading/parsing and 5x when creating a JSON string.
clojure.data.json reading: (dotimes [_ 5] (time (read-json (slurp "foo.json")))) "Elapsed time: 105137.039484 msecs" "Elapsed time: 109517.590644 msecs" "Elapsed time: 114940.018075 msecs" "Elapsed time: 107612.194846 msecs" "Elapsed time: 104434.230607 msecs" nil clj-json reading: (dotimes [_ 5] (time (parse-string (slurp "foo.json") true))) "Elapsed time: 851.541746 msecs" "Elapsed time: 716.894466 msecs" "Elapsed time: 713.257132 msecs" "Elapsed time: 710.379671 msecs" "Elapsed time: 709.358592 msecs" nil clojure.data.json create string: (def foo (read-json (slurp "foo.json"))) (dotimes [_ 5] (time (json-str foo))) "Elapsed time: 1546.511918 msecs" "Elapsed time: 1533.056017 msecs" "Elapsed time: 1534.136322 msecs" "Elapsed time: 1537.893503 msecs" "Elapsed time: 1555.343765 msecs" nil clj-json create string: (def foo (parse-string (slurp "foo.json"))) (dotimes [_ 5] (time (generate-string foo))) "Elapsed time: 375.415311 msecs" "Elapsed time: 298.440444 msecs" "Elapsed time: 272.829368 msecs" "Elapsed time: 271.800466 msecs" "Elapsed time: 273.67808 msecs" nil The JSON file is about 217KB, with vectors containing a couple of thousand JSON objects with nested vector objects between 2-6 levels deep. Granted, clj-json uses a (presumably heavily optimized) Java library as the work horse, while clojure.data.json is pure Clojure. However, I feel the speed penalty is too big of a price to pay in this case. Now, I can use clj-json for my own parsing needs. However, something like clutch (couchdb library) that uses c.d.json behind the scenes may be paying a price in performance that I cannot easily overcome without hacking around inside it in order to swap JSON implementation, rather than tweaking my own code (although, in this case it may be limited to just the JSON string creation). Perhaps there are benefits (of which I'm not aware) to c.d.json that are not available in clj-json, but I'd be hard-pressed to come up with a scenario where I wouldn't pick the significant speed boost of clj-json. Lars Nilsson -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en