From 0e7ab16810fad0d67592146473139ad52db1cf0d Mon Sep 17 00:00:00 2001 From: Deepak Dinesh Date: Fri, 8 Apr 2022 14:41:32 +0530 Subject: [PATCH] form validation benchmark added --- .../benchmarks/form_validate/__init__.py | 0 .../benchmarks/form_validate/benchmark.py | 32 +++++++++++++++++++ .../benchmarks/form_validate/settings.py | 1 + 3 files changed, 33 insertions(+) create mode 100644 djangobench/benchmarks/form_validate/__init__.py create mode 100644 djangobench/benchmarks/form_validate/benchmark.py create mode 100644 djangobench/benchmarks/form_validate/settings.py diff --git a/djangobench/benchmarks/form_validate/__init__.py b/djangobench/benchmarks/form_validate/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangobench/benchmarks/form_validate/benchmark.py b/djangobench/benchmarks/form_validate/benchmark.py new file mode 100644 index 0000000..7f1f887 --- /dev/null +++ b/djangobench/benchmarks/form_validate/benchmark.py @@ -0,0 +1,32 @@ +from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ +from django import forms +from djangobench.utils import run_benchmark + +def form_validator(title): + if title != 'hi': + raise ValidationError( + _('%(title)s is not equal to hi'), + params={'title': title}, + ) + +class BookForm(forms.Form): + title = forms.CharField(max_length=100, validators=[]) + +form = None + +def setup(): + global form + form = BookForm({'title':'hi'}) + +def benchmark(): + form.is_valid() + +run_benchmark( + benchmark, + migrate=False, + meta = { + 'description' : 'speed of form validation' + }, + setup=setup +) \ No newline at end of file diff --git a/djangobench/benchmarks/form_validate/settings.py b/djangobench/benchmarks/form_validate/settings.py new file mode 100644 index 0000000..cf0acc0 --- /dev/null +++ b/djangobench/benchmarks/form_validate/settings.py @@ -0,0 +1 @@ +from djangobench.base_settings import * # NOQA