Python 2.6 JSON decoding performance

后端 未结 7 1311
春和景丽
春和景丽 2020-11-30 05:30

I\'m using the json module in Python 2.6 to load and decode JSON files. However I\'m currently getting slower than expected performance. I\'m using a test case

7条回答
  •  春和景丽
    2020-11-30 05:52

    It may vary by platform, but the builtin json module is based on simplejson, not including the C speedups. I've found simplejson to be as a fast as python-cjson anyway, so I prefer it since it obviously has the same interface as the builtin.

    try:
        import simplejson as json
    except ImportError:
        import json
    

    Seems to me that's the best idiom for awhile, yielding the performance when available while being forwards-compatible.

提交回复
热议问题