Ticket #6668: wrap_test.py

File wrap_test.py, 570 bytes (added by SmileyChris, 7 years ago)

Here's the test file I used (you'll have to copy my new method to new_wrap to run it yourself)

Line 
1from timeit import Timer
2
3TIMES = 20000
4
5from django.utils.text import wrap, new_wrap
6from django.contrib.webdesign import lorem_ipsum
7
8def compare(text):
9    print 'old:', Timer('wrap(%r, 78)' % text, 'from django.utils.text import wrap').timeit(TIMES)
10    print 'new:', Timer('wrap(%r, 78)' % text, 'from django.utils.text import new_wrap as wrap').timeit(TIMES)
11
12print
13print 'Sentence'
14compare(lorem_ipsum.sentence())
15
16print
17print 'Paragraph'
18compare(lorem_ipsum.paragraph())
19
20print
21print '10 Paragraphs'
22compare('\n\n'.join(lorem_ipsum.paragraphs(10, common=False)))
Back to Top