[issue18020] html.escape 10x slower than cgi.escape

2013-07-07 Thread Roundup Robot

Roundup Robot added the comment:

New changeset db5f2b74e369 by Ezio Melotti in branch 'default':
#18020: improve html.escape speed by an order of magnitude.  Patch by Matt 
Bryant.
http://hg.python.org/cpython/rev/db5f2b74e369

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-07-07 Thread Ezio Melotti

Ezio Melotti added the comment:

Fixed, thanks for the report and the patch!

--
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed
versions: +Python 3.4 -Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-06-01 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
assignee:  - ezio.melotti
stage:  - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-28 Thread A.M. Kuchling

A.M. Kuchling added the comment:

Matt's patch looks good to me.  It removes two module-level dicts, but they're 
marked as internal, so that's OK.  There's already a test case that exercises 
html.escape(), so I don't think any additional tests are needed.

--
nosy: +akuchling

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-25 Thread Jakub Wilk

Changes by Jakub Wilk jw...@jwilk.net:


--
nosy: +jwilk

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-20 Thread Florent Xicluna

New submission from Florent Xicluna:

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)
1 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)
10 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)
1 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.

--
components: Library (Lib)
messages: 189641
nosy: ezio.melotti, flox, orsenthil
priority: normal
severity: normal
status: open
title: html.escape 10x slower than cgi.escape
type: performance
versions: Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-20 Thread Graham Dumpleton

Graham Dumpleton added the comment:

Importing the cgi module the first time even in Python 2.X was always very 
expensive. I would suggest you redo the test using timing done inside of the 
script after modules have been imported so as to properly separate module 
import time in both cases from execution time of the specific function.

--
nosy: +grahamd

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-20 Thread Florent Xicluna

Florent Xicluna added the comment:

 I would suggest you redo the test using timing done inside of the script 
 after modules have been imported.

The -s switch takes care of this.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-20 Thread Graham Dumpleton

Graham Dumpleton added the comment:

Whoops. Missed the quoting.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18020] html.escape 10x slower than cgi.escape

2013-05-20 Thread Matt Bryant

Matt Bryant added the comment:

I did a few more tests and am seeing the same speed differences Florent noticed.
It seems reasonable to use .replace() instead, as it does the same thing 
significantly faster.
I've attached a patch doing just this.

--
keywords: +patch
nosy: +Teh Matt
Added file: http://bugs.python.org/file30325/htmlescape.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18020
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com