G
Guru03
For you, it's faster this:
s/>/>/g;
or this:
s/>/>/g if index ($_, '>');
and why?
s/>/>/g;
or this:
s/>/>/g if index ($_, '>');
and why?
Guru03 said:For you, it's faster this:
s/>/>/g;
or this:
s/>/>/g if index ($_, '>');
and why?
For you, it's faster this:
s/>/>/g;
or this:
s/>/>/g if index ($_, '>');
and why?
Guru03 said:For you, it's faster this:
or this:
s/>/>/g if index ($_, '>');
David K. Wall said:[...]Guru03 said:For you, it's faster this:
Use the first one, no need to search the string twice.
Aaron said:and b) when you answer someone's question, you might consider
answering the one they asked.
"David K. Wall" <[email protected]> wrote in message news:[...]Guru03 said:For you, it's faster this:
Use the first one, no need to search the string twice.
Something to keep in mind is that a) Perl doesn't always work that way
and b) when you answer someone's question, you might consider
answering the one they asked.
He didn't ask "which of these would you use", he asked (in admittedly
broken english, but still quite comprehensibly) which of them was
faster.
Isn't it obvious that the first one is faster? Your last line of code
requires Perl to do _two_ things, while the first one only do one
thing;
David K. Wall said:Might I suggest that you read my post too quickly?
Guru03 said:For you, it's faster this:
s/>/>/g;
or this:
s/>/>/g if index ($_, '>');
and why?
Aaron Sherman said:No, I did not. He didn't ask which you would prefer, or how you would
explain a speed difference, he asked which was faster for you, and you
didn't answer that.
I only jump on this because I've asked similar questions over the
years, and I always get people who answer based on gut reaction. With
Perl especially, where the language is defined by a single
implementation with a maze of special-case optimizations, you simply
cannot look at a piece of code and say, "well that one has more steps,
so it's less efficient." It might well work that way in that case, but
unless you run the numbers, you have no real idea.
David K. Wall said:The reason I responded to your post is because it seemed (and seems) to
criticize me and not my answer to the OP. I guess I tried too hard to be
polite and didn't make that point.
Just drop it, ok? You convinced me the first time, I don't need yet another
sermon.
If you heard me criticize YOU at any point, please quote it.
My distinction was on the difference between "which is faster" and
"which would you expect to be faster". That's all. Nothing personal.
Ah, the old "this is the last word, so don't reply!" ;-)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.