I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
Thanks,
Jeremy
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote:
I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I'm guessing this is re.sub (or, more likely, a method sub
Jeremy wrote:
I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
Thanks,
Jeremy
--
http://mail.python.org/mailman/listinfo/python-list
Jeremy wrote:
I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I think it's the subtraction operator. The only way to optimise it is to
reduce the number of subtractions
On Jan 11, 12:54 pm, Carl Banks pavlovevide...@gmail.com wrote:
On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote:
I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize
Jeremy schrieb:
On Jan 11, 12:54 pm, Carl Banks pavlovevide...@gmail.com wrote:
On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote:
I just profiled one of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way
On Mon, Jan 11, 2010 at 12:02 PM, Jeremy jlcon...@gmail.com wrote:
Your guess is correct. I had forgotten that I was using that
function.
I am using the re.sub command to remove trailing whitespace from lines
in a text file. The commands I use are copied below. If you have any
was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I'm guessing this is re.sub (or, more likely, a method sub of an
internal object that is called by re.sub).
If all your script does is to make a bunch of regexp substitutions,
then spending 99
of the code that
don't matter while ignoring the actual bottlenecks.
and discovered that 99% of the time was spent in
{built-in method sub}
What is this function
You don't give us enough information to answer with anything more than a
guess. You know what is in your scripts, we don't. I
On Mon, Jan 11, 2010 at 15:02, Jeremy jlcon...@gmail.com wrote:
I am using the re.sub command to remove trailing whitespace from lines
in a text file. The commands I use are copied below. If you have any
suggestions on how they could be improved, I would love to know.
Just curious, but if
On 1/11/2010 3:02 PM, Jeremy wrote:
I am using the re.sub command to remove trailing whitespace from lines
in a text file.
help(str.rstrip)
Help on method_descriptor:
rstrip(...)
S.rstrip([chars]) - str
Return a copy of the string S with trailing whitespace removed.
If chars is
and discovered that
99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I'm guessing this is re.sub (or, more likely, a method sub of an
internal object that is called by re.sub).
If all your script does is to make a bunch of regexp
On 2010-01-11, Steven D'Aprano st...@remove-this-cybersource.com.au wrote:
[regarding profiling results]
I think you'll find that Python's regex engine is pretty much
optimised as well as it can be, short of a major re-write. But
to quote Jamie Zawinski:
Some people, when confronted
of my Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I'm guessing this is re.sub (or, more likely, a method sub of an
internal object that is called by re.sub).
If all your script does is to make
Philip Semanchuk phi...@semanchuk.com writes:
I second the suggestion to use rstrip(), but for future reference you
should also check out the compile() function in the re module. You
might want to time the code above against a version using a compiled
regex to see how much difference it
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote:
snip
If you can avoid regexes in favour of ordinary string methods, do so. In
general, something like:
source.replace(target, new)
will potentially be much faster than:
regex = re.compile(target)
On Mon, 11 Jan 2010 13:51:48 -0800, Chris Rebert wrote:
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote: snip
If you can avoid regexes in favour of ordinary string methods, do so.
In general, something like:
source.replace(target, new)
will
Python scripts and discovered that 99% of
the time was spent in
{built-in method sub}
What is this function and is there a way to optimize it?
I'm guessing this is re.sub (or, more likely, a method sub of an
internal object that is called by re.sub).
If all your script does is to make
trailingPattern = '(\S*)\ +?\n'
line = re.sub(trailingPattern, '\\1\n', line)
What happens with this?
trailingPattern = '\s+$'
line = re.sub(trailingPattern, '', line)
I'm guessing that $ terminates \s+'s greediness without snarfing the underlying
\n. Then I'm guessing that
19 matches
Mail list logo