Created
April 18, 2011 00:08
-
-
Save vsajip/924626 to your computer and use it in GitHub Desktop.
Time stdlib json versus simplejson on Python 3.2 with and without speedups
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
Python 3.2 numbers | |
================== | |
(jst3)vinay@eta-natty:~/projects/scratch$ python time_json.py --no-speedups | |
Python version: 3.2 (r32:88445, Mar 25 2011, 19:28:28) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson (without speedups): | |
4.585145950317383 | |
Timing stdlib json (without speedups): | |
3.9949100017547607 | |
(jst3)vinay@eta-natty:~/projects/scratch$ python time_json.py | |
Python version: 3.2 (r32:88445, Mar 25 2011, 19:28:28) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson (with speedups): | |
0.3202629089355469 | |
Timing stdlib json (with speedups): | |
0.3200039863586426 | |
Python 2.7 numbers | |
================== | |
(jst)vinay@eta-natty:~/projects/scratch$ python time_json.py --no-speedups | |
Python version: 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson (without speedups): | |
4.49118304253 | |
Timing stdlib json (without speedups): | |
4.2139749527 | |
(jst)vinay@eta-natty:~/projects/scratch$ python time_json.py | |
Python version: 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson (with speedups): | |
0.279826164246 | |
Timing stdlib json (with speedups): | |
0.34278011322 |
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
#!/usr/bin/env python | |
import argparse | |
import sys | |
from timeit import timeit | |
if sys.version_info[0] < 3: | |
from urllib import urlopen | |
else: | |
from urllib.request import urlopen | |
s = urlopen('http://flingo.tv/api2/get_items?app_id=flingo&guid=abc123&howmany=8').read().decode('utf-8') | |
def compare(speedups): | |
if speedups: | |
descr = 'with speedups' | |
else: | |
descr = 'without speedups' | |
import simplejson; simplejson._toggle_speedups(False) | |
sys.modules['_json'] = 0; import json | |
print('Python version: %s' % sys.version) | |
print("%s KiB read" % (float(len(s))/1024)) | |
stmt = 'd = json.loads(s);x = json.dumps(d)' | |
setup='import simplejson as json;from __main__ import s' | |
print('Timing simplejson (%s):' % descr) | |
print(timeit(stmt, setup=setup, number=1000)) | |
setup='import json;from __main__ import s' | |
print('Timing stdlib json (%s):' % descr) | |
print(timeit(stmt, setup=setup, number=1000)) | |
def main(): | |
parser = argparse.ArgumentParser(description='Compare simplejson and ' | |
'stdlib json') | |
parser.add_argument('--no-speedups', dest='speedups', action='store_false', | |
default=True, help='Disable speedups') | |
args = parser.parse_args() | |
compare(args.speedups) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment