Created
November 27, 2016 06:04
-
-
Save pawl/382c655f31dad631ab29775a6c8cad05 to your computer and use it in GitHub Desktop.
new Schema object benchmark
This file contains hidden or 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
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