Created
April 17, 2011 10:32
-
-
Save vsajip/923927 to your computer and use it in GitHub Desktop.
Time stdlib json against simplejson
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 2.7 | |
========== | |
Python version: 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson: | |
0.271898984909 | |
Timing stdlib json: | |
0.338716030121 | |
Python 3.2 | |
========== | |
Python version: 3.2 (r32:88445, Mar 25 2011, 19:28:28) | |
[GCC 4.5.2] | |
11.21484375 KiB read | |
Timing simplejson: | |
0.3150200843811035 | |
Timing stdlib json: | |
0.32146596908569336 |
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 sys | |
import urllib | |
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') | |
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:') | |
print(timeit(stmt, setup=setup, number=1000)) | |
setup='import json;from __main__ import s' | |
print('Timing stdlib json:') | |
print(timeit(stmt, setup=setup, number=1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment