1 | from timeit import Timer
|
---|
2 |
|
---|
3 | TIMES = 20000
|
---|
4 |
|
---|
5 | from django.utils.text import wrap, new_wrap
|
---|
6 | from django.contrib.webdesign import lorem_ipsum
|
---|
7 |
|
---|
8 | def 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 |
|
---|
12 | print
|
---|
13 | print 'Sentence'
|
---|
14 | compare(lorem_ipsum.sentence())
|
---|
15 |
|
---|
16 | print
|
---|
17 | print 'Paragraph'
|
---|
18 | compare(lorem_ipsum.paragraph())
|
---|
19 |
|
---|
20 | print
|
---|
21 | print '10 Paragraphs'
|
---|
22 | compare('\n\n'.join(lorem_ipsum.paragraphs(10, common=False)))
|
---|