Skip to content

Instantly share code, notes, and snippets.

@showyou
Created January 30, 2011 02:57
Show Gist options
  • Save showyou/802471 to your computer and use it in GitHub Desktop.
Save showyou/802471 to your computer and use it in GitHub Desktop.
import msgpack
import time
from random import randint
start_time = time.time()
for i in xrange(1000000):
a = randint(1,1000)
b = randint(1,1000)
setdata = (a, b)
data = msgpack.packb(setdata)
#print data
result = msgpack.unpackb(data)
#print result
end_time = time.time() - start_time
from random import randint
start_time = time.time()
packer = msgpack.Packer()
for i in xrange(1000000):
a = randint(1,1000)
b = randint(1,1000)
setdata = (a, b)
data = packer.pack(setdata)
#print data
result = msgpack.unpackb(data)
#print result
end_time = time.time() - start_time
print "end_time", end_time
#!/usr/bin/env python
import cPickle as pickle
import time
from random import randint
start_time = time.time()
for i in xrange(1000000):
a = randint(1,1000)
b = randint(1,1000)
setdata = (a, b)
data = pickle.dumps(setdata)
#print data
result = pickle.loads(data)
#print result
end_time = time.time() - start_time
print "end_time", end_time
@showyou
Copy link
Author

showyou commented Jan 30, 2011

次。msgpacktime2.pyでも同じことやってみた。

cocona yuki% python msgpacktime2.py [/gitrep/python/temp]
end_time 7.24350881577
cocona yuki% python msgpacktime2.py [
/gitrep/python/temp]
end_time 6.99837803841
cocona yuki% python msgpacktime2.py [/gitrep/python/temp]
end_time 7.29973101616
cocona yuki% python msgpacktime2.py [
/gitrep/python/temp]
end_time 7.41284203529
cocona yuki% python msgpacktime2.py [~/gitrep/python/temp]
end_time 6.91521000862
やばい、これは早い

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment