Skip to content
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

model validation benchmark added #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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.
20 changes: 20 additions & 0 deletions djangobench/benchmarks/model_validate/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

from djangobench.utils import run_benchmark


def setup():
global Book
from model_validate.models import Book

def benchmark():
global Book
b = Book(title="hi")
b.full_clean()

run_benchmark(
benchmark=benchmark,
meta={
'description' : 'Model validation benchmark'
},
setup=setup
)
14 changes: 14 additions & 0 deletions djangobench/benchmarks/model_validate/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from django.db import models

def validate_title(title):
if title != 'hi':
raise ValidationError(
_('%(title)s is not hi'),
params={'title': title},
)

class Book(models.Model):
title = models.CharField(max_length=100, validators=[validate_title])
3 changes: 3 additions & 0 deletions djangobench/benchmarks/model_validate/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from djangobench.base_settings import * # NOQA

INSTALLED_APPS = ['model_validate']