Created
January 15, 2021 16:32
-
-
Save smithdc1/4fb47038a8d34f14764c58e98b213e61 to your computer and use it in GitHub Desktop.
Benchmark for DecimalField.to_python()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.global_settings import INSTALLED_APPS | |
import django | |
from django.conf import settings | |
from django.forms import DecimalField | |
import pyperf | |
settings.configure(INSTALLED_APPS= ('__main__',)) | |
django.setup() | |
def test(loops): | |
range_it = range(loops) | |
f = DecimalField(max_digits=2, decimal_places=2) | |
t0 = pyperf.perf_counter() | |
# repeat to reduce impact of for loop | |
for loop in range_it: | |
f.clean('.01 ') | |
f.clean('.01') | |
f.clean(' .01') | |
f.clean(' .01 ') | |
f.clean('.01 ') | |
f.clean('.01') | |
f.clean(' .01') | |
f.clean(' .01 ') | |
f.clean('.01 ') | |
f.clean('.01') | |
f.clean(' .01') | |
f.clean(' .01 ') | |
f.clean('.01 ') | |
f.clean('.01') | |
f.clean(' .01') | |
f.clean(' .01 ') | |
return pyperf.perf_counter() - t0 | |
runner = pyperf.Runner() | |
runner.bench_time_func('Decimal Field', test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before
After
c.3% faster