string repr in 2.1
Michael Hudson
mwh at python.net
Tue May 29 08:56:11 EDT 2001
Michael Hudson <mwh at python.net> writes:
> Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>
>
> > On related notes if repr no longer does octal escapes does string
> > input still accept them?
>
> Yes! Upgrading isn't meant to be *that* much of an adventure.
>
> > Also my trial of the 2.0 code versus an initial 2.1 coding reveals
> > that an re based approach is very slow :( Anyone know simply what's
> > involved in doing a codec?
>
> Try this instead:
>
> def _make_dict():
> d = {}
> for c in range(ord(' ')) + range(0x7F,0xFF):
^^^^
This should be 0x100, sorry.
[snip]
> It can be rewritten in C if you're really keen, when it'll probably
> run somewhat faster than _escape20
It does:
Time for 1000x4 uses of <function _escape20 at 0x8124b54> = 0.54"
Time for 1000x4 uses of <function _escape21 at 0x8121914> = 2.28"
Time for 1000x4 uses of <function _escape21_mwh at 0x80cb99c> = 0.84"
Time for 1000x4 uses of <function <lambda> at 0x8124b1c> = 0.33"
(and that's not optimal because the C function I borrowed (from
pyrepl) does more work; could probably get it down to about 0.20").
Cheers,
M.
--
MAN: How can I tell that the past isn't a fiction designed to
account for the discrepancy between my immediate physical
sensations and my state of mind?
-- The Hitch-Hikers Guide to the Galaxy, Episode 12
More information about the Python-list
mailing list