Skip to content

Instantly share code, notes, and snippets.

@pawl
Created November 27, 2016 06:04
Show Gist options
  • Save pawl/382c655f31dad631ab29775a6c8cad05 to your computer and use it in GitHub Desktop.
Save pawl/382c655f31dad631ab29775a6c8cad05 to your computer and use it in GitHub Desktop.
new Schema object benchmark
from jsonschema import validate, Schema
# A sample schema, like what we'd get from json.load()
schema = {
"type": "object",
"properties": {
"price": {"type": "number"},
"name": {"type": "string"},
},
}
schema_obj = Schema(schema)
def test1():
for i in range(10):
validate({"name": "Eggs", "price": 34.99}, schema)
def test2():
for i in range(10):
schema_obj.validate({"name": "Eggs", "price": 34.99})
if __name__ == '__main__':
import timeit
print(timeit.timeit("test1()", setup="from __main__ import test1", number=1000))
# 4.12520503998
print(timeit.timeit("test2()", setup="from __main__ import test2", number=1000))
# 0.163820981979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment