Message189641
I noticed the convenient ``html.escape`` in Python 3.2 and ``cgi.escape`` is marked as deprecated.
However, the former is an order of magnitude slower than the latter.
$ python3 --version
Python 3.3.2
With html.escape:
$ python3 -m timeit -s "from html import escape as html; from cgi import escape; s = repr(copyright)" "h = html(s)"
10000 loops, best of 3: 48.7 usec per loop
$ python3 -m timeit -s "from html import escape as html; from cgi import escape; s = repr(copyright) * 19" "h = html(s)"
1000 loops, best of 3: 898 usec per loop
With cgi.escape:
$ python3 -m timeit -s "from html import escape as html; from cgi import escape; s = repr(copyright)" "h = escape(s)"
100000 loops, best of 3: 7.42 usec per loop
$ python3 -m timeit -s "from html import escape as html; from cgi import escape; s = repr(copyright) * 19" "h = escape(s)"
10000 loops, best of 3: 21.5 usec per loop
Since this kind of function is called frequently in template engines, it makes a difference.
Of course C replacements are available on PyPI: MarkupSafe or Webext
But it would be nice to restore the performance of cgi.escape with a pragmatic `.replace(` approach. |
|
Date |
User |
Action |
Args |
2013-05-20 08:21:38 | flox | set | recipients:
+ flox, orsenthil, ezio.melotti |
2013-05-20 08:21:38 | flox | set | messageid: <1369038098.34.0.795942514317.issue18020@psf.upfronthosting.co.za> |
2013-05-20 08:21:38 | flox | link | issue18020 messages |
2013-05-20 08:21:37 | flox | create | |
|