in reply to Re^3: The indisputable speed of tr///
in thread The indisputable speed of tr///
I wonder ... if all you were doing was some transliteration why would you bother with the lines at all?
Good point. I now have the code altered in test to use sysread to read in 128KB at a time, and there is definitely a boost there. Probably roll that into prod with the next release. Thanks!
why would you spend time "figuring out reasonable character classes? If you have the mapping hash, just build the tr/// out of it.
I started there, actually, with code that looks something like this:
my %rot = ( 'A' => 'N','B' => 'O','C' => 'P','D' => 'Q','E' => 'R','F' => 'S', 'G' => 'T','H' => 'U','I' => 'V','J' => 'W','K' => 'X','L' => 'Y', 'M' => 'Z','N' => 'A','O' => 'B','P' => 'C','Q' => 'D','R' => 'E', 'S' => 'F','T' => 'G','U' => 'H','V' => 'I','W' => 'J','X' => 'K', 'Y' => 'L','Z' => 'M','a' => 'n','b' => 'o','c' => 'p','d' => 'q', 'e' => 'r','f' => 's','g' => 't','h' => 'u','i' => 'v','j' => 'w', 'k' => 'x','l' => 'y','m' => 'z','n' => 'a','o' => 'b','p' => 'c', 'q' => 'd','r' => 'e','s' => 'f','t' => 'g','u' => 'h','v' => 'i', 'w' => 'j','x' => 'k','y' => 'l','z' => 'm', ); my ($tr_a, $tr_b); for (keys %rot) { $tr_a.=$_; $tr_b.=$rot{$_} } print "tr/$tr_a/$tr_b/;\n";
However, I wasn't kidding when I said that ROT-13 is a simplified case of the actual problem! I spent some time finding the char classes, not for runtime efficiency, but for readability/maintainability. There's a reasonable chance of the rules changing, and a tr/// with 300-or-so-char clauses is mighty unreadable.
The string eval is an interesting solution, and one I will have to play around with -- unfortunately, it won't be allowed in prod without an exception filing (string evals are against our coding standards), so there will have to be significant benefit to get it approved. Still, something I hadn't considered, so I thank you for that...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: The indisputable speed of tr///
by ikegami (Patriarch) on Jun 27, 2006 at 16:59 UTC | |
Re^5: The indisputable speed of tr///
by runrig (Abbot) on Jun 27, 2006 at 17:27 UTC | |
by radiantmatrix (Parson) on Jun 28, 2006 at 14:04 UTC | |
Re^5: The indisputable speed of tr///
by Jenda (Abbot) on Jun 27, 2006 at 17:30 UTC | |
by Hue-Bond (Priest) on Jun 27, 2006 at 18:07 UTC | |
Re^5: The indisputable speed of tr///
by duff (Parson) on Jun 27, 2006 at 18:32 UTC |