in reply to transliterate
_____________________________________________________
Jeff japhy Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: transliterate
by dsb (Chaplain) on Jul 27, 2001 at 21:55 UTC | |
NOTE: I did use counts between 250,000 and 2,000,000 as well. Maybe its my system, but I thought that this was strange. Amel - f.k.a. - kel | [reply] [d/l] |
by japhy (Canon) on Jul 27, 2001 at 22:01 UTC | |
_____________________________________________________ | [reply] |
by tye (Sage) on Jul 27, 2001 at 22:31 UTC | |
Another thing to try is to interleave duplicate tests so that start-up "settling in" doesn't scew the results: which gave me these results:
Which (update doesn't) show tr to be faster than s but only slightly so. The fact is that the speed difference between s and tr is trivial for such cases. If you have really long strings, then tr becomes more attractive. But when tr really becomes attractive is when you want to replace lots of different characters with lots of different characters. For example, write a ROT13 encoder with s and you'll see what I mean. Update: Sorry, I read the numbers backward. Not that it matters much to me as I don't really care whether I can do 0.7 million per second or 1.2 million per second. (: The point is that they are both fast and fairly close to each other in speed. Thanks to petral for pointing my mistake out to me. Swapping out s for tr for this case is really another case of premature optimization. But making the choice of using tr in the beginning for this case is probably good defensive programming. (: - tye (but my friends call me "Tye") | [reply] [d/l] [select] |
by dsb (Chaplain) on Jul 27, 2001 at 23:54 UTC | |
The preceding output the following: So by the looks of the runs per second statistic that tr is indeed faster than s///. What dondelelcaro mentioned about v5.005003 having a slower version of tr could be relevant though, as that is what I'm running. Amel - f.k.a. - kel | [reply] [d/l] [select] |
by dondelelcaro (Monk) on Jul 27, 2001 at 22:17 UTC | |
5.005_03 seems to have a really slow tr///, that actually is slower than s/// (singe celeron 466)
However, 5.6.1 (on a dual p3 800) tr seems to be almost twice as fast.
I don't know too much about the tr/// and s/// code, but it looks like someone went and optimized tr/// between 5.005 and 5.6.1. (Would someone who knows (japhy?) please comment on this?) | [reply] [d/l] [select] |
by trantor (Chaplain) on Jul 27, 2001 at 22:39 UTC | |
It would be interesting to compare the results using Unicode strings. In this case, the difference between a character by character scan and a Finite State Machine could be greater, although the FSM generated by <ODE>s/ /+/g</CODE> is so simple that it is probably a character by character scan. -- TMTOWTDI | [reply] |