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