Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Created September 5, 2016 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwinex/e82da222888ce0f4e365e046719af91c to your computer and use it in GitHub Desktop.
Save paulwinex/e82da222888ce0f4e365e046719af91c to your computer and use it in GitHub Desktop.
import json, time
d1 = 'name|key'
d2 = json.dumps({'username':'name', 'chanel':'key'})
count = 1000000
st = time.time()
for i in xrange(count):
name, chan = d1.split('|')
r1 = time.time()-st
print 'Split: %s' % r1
st = time.time()
for i in xrange(count):
data = json.loads(d2)
r2 = time.time()-st
print 'Parse JSON: %s' % r2
print 'Faster %s times' % (r2/r1)
'''
Split: 0.335999965668
Parse JSON: 3.82699990273
Faster 11.3898818267 times
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment