-
-
Save dchentech/02dca2bcc8b0ef1bbfb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| '''cjson, jsonlib, simplejson, and yajl also use C code | |
| demjson did not use C code, but was too painfully slow to benchmark | |
| (took about 20 seconds for these tests) | |
| ''' | |
| import json | |
| import sys | |
| import time | |
| # Compact between Python literal and JSON format. | |
| false = False | |
| true = True | |
| with open('doc.json') as f: | |
| decoded = f.read() | |
| encoded = json.loads(decoded) | |
| def test_encodes(modules): | |
| encode_times = {} | |
| for json_module in modules: | |
| start = time.clock() | |
| for _ in xrange(10000): | |
| json_module.loads(decoded) | |
| total_time = time.clock() - start | |
| assert json_module.loads(decoded) == encoded, "decoded:%s, encoded:%s" % (decoded, encoded) | |
| encode_times[json_module.__name__] = total_time | |
| return encode_times | |
| def test_decodes(modules): | |
| decode_times = {} | |
| for json_module in modules: | |
| start = time.clock() | |
| for _ in xrange(10000): | |
| json_module.dumps(encoded) | |
| total_time = time.clock() - start | |
| assert json_module.loads(json_module.dumps(encoded)) == encoded, "decoded:%s, encoded:%s" % (decoded, encoded) | |
| decode_times[json_module.__name__] = total_time | |
| return decode_times | |
| def printer(mapping): | |
| ''' mapping maps module name to time''' | |
| for k, v in mapping.iteritems(): | |
| print '%s: %ss' % (k, v) | |
| def main(): | |
| print 'JSON Benchmark' | |
| try: | |
| import __pypy__ | |
| __pypy__ # follow PEP8, make __pypy__ used. | |
| except ImportError: | |
| # we are using CPython | |
| print sys.version | |
| import cjson | |
| import jsonlib | |
| import simplejson | |
| import ujson | |
| import yajl | |
| jsonlib.loads = jsonlib.read | |
| jsonlib.dumps = jsonlib.write | |
| cjson.loads = cjson.decode | |
| cjson.dumps = cjson.encode | |
| from collections import namedtuple | |
| python = namedtuple("Python", ["loads", "dumps"]) | |
| python.loads = eval | |
| python.dumps = str | |
| modules = [cjson, json, jsonlib, simplejson, ujson, yajl, python] | |
| else: | |
| # we are using PyPy | |
| print sys.version | |
| modules = [json] | |
| print '-----------------------------' | |
| print 'ENCODING' | |
| printer(test_encodes(modules)) | |
| print '' | |
| print 'DECODING' | |
| printer(test_decodes(modules)) | |
| if __name__ == '__main__': | |
| main() |
This file contains hidden or 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
| { | |
| "web-app": { | |
| "servlet": [ | |
| { | |
| "servlet-name": "cofaxCDS", | |
| "servlet-class": "org.cofax.cds.CDSServlet", | |
| "init-param": { | |
| "configGlossary:installationAt": "Philadelphia, PA", | |
| "configGlossary:adminEmail": "[email protected]", | |
| "configGlossary:poweredBy": "Cofax", | |
| "configGlossary:poweredByIcon": "/images/cofax.gif", | |
| "configGlossary:staticPath": "/content/static", | |
| "templateProcessorClass": "org.cofax.WysiwygTemplate", | |
| "templateLoaderClass": "org.cofax.FilesTemplateLoader", | |
| "templatePath": "templates", | |
| "templateOverridePath": "", | |
| "defaultListTemplate": "listTemplate.htm", | |
| "defaultFileTemplate": "articleTemplate.htm", | |
| "useJSP": false, | |
| "jspListTemplate": "listTemplate.jsp", | |
| "jspFileTemplate": "articleTemplate.jsp", | |
| "cachePackageTagsTrack": 200, | |
| "cachePackageTagsStore": 200, | |
| "cachePackageTagsRefresh": 60, | |
| "cacheTemplatesTrack": 100, | |
| "cacheTemplatesStore": 50, | |
| "cacheTemplatesRefresh": 15, | |
| "cachePagesTrack": 200, | |
| "cachePagesStore": 100, | |
| "cachePagesRefresh": 10, | |
| "cachePagesDirtyRead": 10, | |
| "searchEngineListTemplate": "forSearchEnginesList.htm", | |
| "searchEngineFileTemplate": "forSearchEngines.htm", | |
| "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", | |
| "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", | |
| "dataStoreUser": "sa", | |
| "dataStorePassword": "dataStoreTestQuery", | |
| "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", | |
| "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", | |
| "dataStoreInitConns": 10, | |
| "dataStoreMaxConns": 100, | |
| "dataStoreConnUsageLimit": 100, | |
| "dataStoreLogLevel": "debug", | |
| "maxUrlLength": 500 | |
| } | |
| }, | |
| { | |
| "servlet-name": "cofaxEmail", | |
| "servlet-class": "org.cofax.cds.EmailServlet", | |
| "init-param": { | |
| "mailHost": "mail1", | |
| "mailHostOverride": "mail2" | |
| } | |
| }, | |
| { | |
| "servlet-name": "cofaxAdmin", | |
| "servlet-class": "org.cofax.cds.AdminServlet" | |
| }, | |
| { | |
| "servlet-name": "fileServlet", | |
| "servlet-class": "org.cofax.cds.FileServlet" | |
| }, | |
| { | |
| "servlet-name": "cofaxTools", | |
| "servlet-class": "org.cofax.cms.CofaxToolsServlet", | |
| "init-param": { | |
| "templatePath": "toolstemplates/", | |
| "log": 1, | |
| "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", | |
| "logMaxSize": "", | |
| "dataLog": 1, | |
| "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", | |
| "dataLogMaxSize": "", | |
| "removePageCache": "/content/admin/remove?cache=pages&id=", | |
| "removeTemplateCache": "/content/admin/remove?cache=templates&id=", | |
| "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", | |
| "lookInContext": 1, | |
| "adminGroupID": 4, | |
| "betaServer": true | |
| } | |
| } | |
| ], | |
| "servlet-mapping": { | |
| "cofaxCDS": "/", | |
| "cofaxEmail": "/cofaxutil/aemail/*", | |
| "cofaxAdmin": "/admin/*", | |
| "fileServlet": "/static/*", | |
| "cofaxTools": "/tools/*" | |
| }, | |
| "taglib": { | |
| "taglib-uri": "cofax.tld", | |
| "taglib-location": "/WEB-INF/tlds/cofax.tld" | |
| } | |
| } | |
| } |
This file contains hidden or 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
| jsonlib==1.6.1 | |
| python-cjson==1.0.5 | |
| simplejson==2.1.6 | |
| ujson==1.4 | |
| yajl==0.3.5 |
This file contains hidden or 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
| CPython | |
| JSON Benchmark | |
| 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) | |
| [GCC 4.5.2] | |
| ----------------------------- | |
| ENCODING | |
| simplejson: 0.45s | |
| cjson: 0.45s | |
| ujson: 0.46s | |
| jsonlib: 0.65s | |
| json: 1.02s | |
| yajl: 0.7s | |
| DECODING | |
| simplejson: 0.73s | |
| cjson: 0.83s | |
| ujson: 0.41s | |
| jsonlib: 0.48s | |
| json: 0.6s | |
| yajl: 0.59s | |
| PyPy | |
| JSON Benchmark | |
| 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:38) | |
| [PyPy 1.5.0-alpha0 with GCC 4.4.3] | |
| ----------------------------- | |
| ENCODING | |
| json: 2.839568s | |
| DECODING | |
| json: 5.551157s | |
| JSON Benchmark | |
| 2.7.9 (default, Jan 14 2015, 12:59:47) | |
| [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] | |
| ----------------------------- | |
| ENCODING | |
| simplejson: 0.200864s | |
| cjson: 0.335475s | |
| ujson: 0.169225s | |
| jsonlib: 0.297341s | |
| Python: 2.336938s | |
| json: 0.548224s | |
| yajl: 0.322109s | |
| DECODING | |
| simplejson: 0.302664s | |
| cjson: 0.276507s | |
| ujson: 0.115845s | |
| jsonlib: 0.194297s | |
| Python: 0.284689s | |
| json: 0.250216s | |
| yajl: 0.271826s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment