Skip to content

Form validation benchmark added #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions benchmarks/form_benchmarks/form_validate/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django import forms
from django.core.exceptions import ValidationError

from ...utils import bench_setup


def form_validator(title):
if title != "hi":
raise ValidationError("title is not hi")


class BookForm(forms.Form):
title = forms.CharField(max_length=100, validators=[form_validator])


class FormValidate:
def setup(self):
bench_setup()
self.form = BookForm({"title": "hi"})
self.invalid_form = BookForm({"title": "abc"})

def time_form_validate(self):
self.form.is_valid()

def time_form_invalid(self):
self.invalid_form.is_valid()