mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
Add benchmark for valideer (#670)
* Add benchmark for valideer * valideer version and update benchmarks * add change * correct benchmarks
This commit is contained in:
committed by
Samuel Colvin
parent
f10680dd75
commit
69737c3aa3
@@ -0,0 +1 @@
|
||||
Add benchmarks for `valideer`
|
||||
@@ -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
|
||||
|
||||
+5
-1
@@ -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
|
||||
]
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user