Last active
December 27, 2015 15:18
-
-
Save AtnNn/7346211 to your computer and use it in GitHub Desktop.
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 rethinkdb as r | |
import rethinkdb.ast | |
import rethinkdb.net | |
import sys | |
import types | |
import json | |
import ujson | |
from timeit import timeit | |
json_str = sys.argv[1] | |
c = r.connect() | |
q1 = (r.json(json_str), lambda x: x) | |
q2 = (r.json(json_str).coerce_to('STRING'), json.loads) | |
q3 = (r.json(json_str).coerce_to('STRING'), ujson.loads) | |
def runq(q): | |
return q[1](q[0].run(c)) | |
print runq(q1) | |
print runq(q2) | |
print runq(q3) | |
number = 10000 | |
print "PROTOBUF", r.protobuf_implementation, ":", timeit(lambda: runq(q1), number=number) | |
print "JSON:", timeit(lambda: runq(q2), number=number) | |
print "UJSON:", timeit(lambda: runq(q3), number=number) |
Author
AtnNn
commented
Nov 8, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment