-
Notifications
You must be signed in to change notification settings - Fork 2
Perf. vs jsonschema
Rob edited this page Jun 13, 2014
·
2 revisions
Warmongo used to be based off of Julian Berman's jsonschema module, which is an excellent and very comprehensive implementation of the JSON Schema specification. The downside is that after profiling, we found the performance to be unacceptable for our needs - our system is processing thousands of JSON messages per second, all of which need to be validated. We refactored warmongo to use it's own internal validation mechanism which is only a partial implementation of JSON Schema, however is much faster.
Here is a benchmarking script:
import jsonschema
import warmongo
from time import time
iterations = 10000
schema = {
"name": "Test",
"type": "object",
"properties": {
"blah": {"type": "number"},
"blark": {
"type": "array",
"items": {"type": "string"}
}
}
}
to_validate = {
"blah": 5,
"blark": ["a", "b", "cd"]
}
ToValidate = warmongo.model_factory(schema)
print "Validating %d times" % iterations
print "testing jsonschema..."
start = time()
for i in range(iterations):
jsonschema.validate(to_validate, schema)
jsonschema_took = time() - start
print "testing warmongo..."
start = time()
for i in range(iterations):
ToValidate(to_validate)
warmongo_took = time() - start
print "jsonschema: %.4f seconds" % jsonschema_took
print "warmongo: %.4f seconds" % warmongo_took
print "Warmongo speedup: %.2f%%" % ((jsonschema_took / warmongo_took - 1.0) * 100)
Here is the output:
$ python test.py
Validating 10000 times
testing jsonschema...
testing warmongo...
jsonschema: 7.1541 seconds
warmongo: 0.3249 seconds
Warmongo speedup: 2101.62%
Moral of the story: if you need comprehensive features, jsonschema is your best friend. If you need raw performance, warmongo is much faster.