#36137: Simple performance test using timeit and django.test.Client leads to 
using
all available memory
-----------------------------------+--------------------------------------
     Reporter:  Vinay Sajip        |                    Owner:  (none)
         Type:  Bug                |                   Status:  closed
    Component:  Testing framework  |                  Version:  5.1
     Severity:  Normal             |               Resolution:  invalid
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Comment (by Simon Charette):

 Per [https://docs.python.org/3/library/timeit.html#timeit.Timer.timeit
 Python docs] on `timeit`

 > By default, `timeit()` temporarily turns off garbage collection during
 the timing. The advantage of this approach is that it makes independent
 timings more comparable. The disadvantage is that GC may be an important
 component of the performance of the function being measured. If so, GC can
 be re-enabled as the first statement in the `setup` string.

 Enabling garbage collection, which is a necessity if you're going to be
 creating 2M requests, also bounds the memory usage

 {{{#!python
     def test_render_performance(self):
         n = 2000000
         t = timeit.timeit(setup="gc.enable();from django.test import
 Client; c = Client(headers={'user-agent': 'Mozilla/5.0 (X11; Linux x86_64;
 rv:134.0) Gecko/20100101 Firefox/134.0'})",
                           stmt="c.get('/admin/')", number=n)
         print(f'{int(t * 1000/n)} msecs')
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36137#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701949f3091c7-854291f6-4c17-43c5-88ad-ec58378e7478-000000%40eu-central-1.amazonses.com.

Reply via email to