Movatterモバイル変換
[0]ホーム
[Python-Dev] Performance of u()
Antoine Pitrousolipsis at pitrou.net
Sun Feb 26 18:53:31 CET 2012
On Sat, 25 Feb 2012 19:13:26 -0800Guido van Rossum <guido at python.org> wrote:> If this can encourage more projects to support Python 3 (even if it's> only 3.3 and later) and hence improve adoption of Python 3, I'm all> for it.>> A small quibble: I'd like to see a benchmark of a 'u' function implemented in C.Even without implementing it in C, caching the results makes it muchless prohibitive in tight loops:if sys.version_info >= (3, 0): def u(value): return valueelse: def u(value, _lit_cache={}): if value in _lit_cache: return _lit_cache[value] s = _lit_cache[value] = unicode(value, 'unicode-escape') return su'\N{SNOWMAN}barbaz' -> 100000000 loops, best of 3: 0.00928 usec per loopu('\N{SNOWMAN}barbaz') -> 10000000 loops, best of 3: 0.15 usec per loopu'foobarbaz_%d' % x -> 1000000 loops, best of 3: 0.424 usec per loopu('foobarbaz_%d') % x -> 1000000 loops, best of 3: 0.598 usec per loopRegardsAntoine.
More information about the Python-Devmailing list
[8]ページ先頭