forked from jazzband/django-floppyforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
51 lines (40 loc) · 1.21 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Compares the rendering speed between Django forms and django-floppyforms
Usage: DJANGO_SETTINGS_MODULE=benchmark python benchmark.py [--cache]
"""
import sys
import timeit
django = """from django import forms
class DjangoForm(forms.Form):
text = forms.CharField()
slug = forms.SlugField()
some_bool = forms.BooleanField()
email = forms.EmailField()
date = forms.DateTimeField()
file_ = forms.FileField()
rendered = DjangoForm().as_p()"""
flop = """import floppyforms as forms
class FloppyForm(forms.Form):
text = forms.CharField()
slug = forms.SlugField()
some_bool = forms.BooleanField()
email = forms.EmailField()
date = forms.DateTimeField()
file_ = forms.FileField()
rendered = FloppyForm().as_p()"""
def time(stmt):
t = timeit.Timer(stmt=stmt)
return t.timeit(number=1000)
if __name__ == '__main__':
print "Plain Django:", time(django)
print "django-floppyforms:", time(flop)
INSTALLED_APPS = (
'floppyforms'
)
if '--cache' in sys.argv:
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)