Created
March 11, 2019 06:06
-
-
Save twlz0ne/bc8b4f11c1e7b13779f77dc5f42070e3 to your computer and use it in GitHub Desktop.
benchmark native and json.el #emacs
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
;;; Usage: /path/to/emacs -Q --batch -l /path/to/benchmark-native-json.el | |
;;; Date: 2019-03-10_15.53.34 | |
(require 'json) | |
(defconst json-string | |
;; @from https://github.com/syohex/emacs-parson/blob/master/bench/bench.json | |
"{ | |
\"glossary\": { | |
\"title\": \"example glossary\", | |
\"GlossDiv\": { | |
\"title\": \"S\", | |
\"GlossList\": { | |
\"GlossEntry\": { | |
\"ID\": \"SGML\", | |
\"SortAs\": \"SGML\", | |
\"GlossTerm\": \"Standard Generalized Markup Language\", | |
\"Acronym\": \"SGML\", | |
\"Abbrev\": \"ISO 8879:1986\", | |
\"GlossDef\": { | |
\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\", | |
\"GlossSeeAlso\": [ | |
\"GML\", | |
\"XML\" | |
] | |
}, | |
\"GlossSee\": \"markup\" | |
} | |
} | |
} | |
} | |
}") | |
(defmacro run-benchmark (exp) | |
`(message "%-66S ;; => %s" | |
',exp | |
(let ((inhibit-message t)) | |
(with-temp-buffer | |
,exp)))) | |
(message (replace-regexp-in-string "\n" "" (emacs-version))) | |
(run-benchmark (benchmark '100000 '(json-serialize nil))) | |
(run-benchmark (benchmark '100000 '(json-encode nil))) | |
(run-benchmark (benchmark '100000 '(json-serialize [1 2 3 4 5]))) | |
(run-benchmark (benchmark '100000 '(json-encode [1 2 3 4 5]))) | |
(run-benchmark (benchmark '100000 '(json-parse-string "[true]"))) | |
(run-benchmark (benchmark '100000 '(json-read-from-string "[true]"))) | |
(run-benchmark (benchmark '100000 '(json-parse-string "{}"))) | |
(run-benchmark (benchmark '100000 '(json-read-from-string "{}"))) | |
(run-benchmark (benchmark '100000 '(json-parse-string json-string))) | |
(run-benchmark (benchmark '100000 '(json-read-from-string json-string))) | |
;;; benchmark-native-json.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems json.c was improved in recents months.
https://github.com/emacs-mirror/emacs/commits/master/src/json.c