diff --git a/670-gsakkis.md b/670-gsakkis.md new file mode 100644 index 0000000..91ef628 --- /dev/null +++ b/670-gsakkis.md @@ -0,0 +1 @@ +Add benchmarks for `valideer` diff --git a/benchmarks/requirements.txt b/benchmarks/requirements.txt index 76530f7..fefc275 100644 --- a/benchmarks/requirements.txt +++ b/benchmarks/requirements.txt @@ -4,5 +4,6 @@ django # pyup: ignore djangorestframework # pyup: ignore #marshmallow # pyup: ignore toastedmarshmallow # pyup: ignore +valideer # pyup: ignore attr # pyup: ignore cattrs # pyup: ignore diff --git a/benchmarks/run.py b/benchmarks/run.py index b36d211..1a0ae78 100644 --- a/benchmarks/run.py +++ b/benchmarks/run.py @@ -32,6 +32,10 @@ try: from test_toasted_marshmallow import TestToastedMarshmallow except Exception: TestToastedMarshmallow = None +try: + from test_valideer import TestValideer +except Exception: + TestValideer = None try: from test_cattr import TestCAttr @@ -47,7 +51,7 @@ random = random.SystemRandom() # in order of performance for csv other_tests = [ t for t in - [TestCAttr, TestToastedMarshmallow, TestMarshmallow, TestTrafaret, TestDRF] + [TestCAttr, TestValideer, TestToastedMarshmallow, TestMarshmallow, TestTrafaret, TestDRF] if t is not None ] diff --git a/benchmarks/test_valideer.py b/benchmarks/test_valideer.py new file mode 100644 index 0000000..353122a --- /dev/null +++ b/benchmarks/test_valideer.py @@ -0,0 +1,47 @@ +import re +import subprocess + +import dateutil.parser +import valideer as V + +# valideer appears to provide no way of getting the installed version +p = subprocess.run(['pip', 'freeze'], stdout=subprocess.PIPE, encoding='utf8', check=True) +valideer_version = re.search(r'valideer==(.+)', p.stdout).group(1) + + +class TestValideer: + package = 'valideer' + version = valideer_version + + def __init__(self, allow_extra): + schema = { + '+id': int, + '+client_name': V.String(max_length=255), + '+sort_index': float, + 'client_phone': V.Nullable(V.String(max_length=255)), + 'location': {'latitude': float, 'longitude': float}, + 'contractor': V.Range(V.AdaptTo(int), min_value=1), + 'upstream_http_referrer': V.Nullable(V.String(max_length=1023)), + '+grecaptcha_response': V.String(min_length=20, max_length=1000), + 'last_updated': V.AdaptBy(dateutil.parser.parse), + 'skills': V.Nullable( + [ + { + '+subject': str, + '+subject_id': int, + '+category': str, + '+qual_level': str, + '+qual_level_id': int, + 'qual_level_ranking': V.Nullable(float, default=0), + } + ], + default=[], + ), + } + self.validator = V.parse(schema, additional_properties=allow_extra) + + def validate(self, data): + try: + return True, self.validator.validate(data) + except V.ValidationError as e: + return False, str(e) diff --git a/docs/.benchmarks_table.md b/docs/.benchmarks_table.md index 8535f5f..54bfb06 100644 --- a/docs/.benchmarks_table.md +++ b/docs/.benchmarks_table.md @@ -4,6 +4,7 @@ Package | Version | Relative Performance | Mean validation time --- | --- | --- | --- pydantic | `1.1` | | 46.1μs cattr | `19.3.0` | 1.3x slower | 62.1μs +valideer | `0.4.2` | 1.4x slower | 62.6μs marshmallow | `2.15.1` | 2.9x slower | 132.7μs toasted-marshmallow | `2.15.2post1` | 2.9x slower | 134.1μs trafaret | `2.0.0` | 3.3x slower | 153.5μs