in reply to Sorting characters within a string
If I were doing this in assembly, and I wanted raw speed I'd:
if (substr($base,0,1) eq 'a') { if (substr($base,1,1) eq 'a') { return 'aa'; } if (substr($base,1,1) eq 'b') { return 'ab' } } if (substr($base,0,1) eq 'b') { if (substr($base,1,1) eq 'a') { return 'ab' } if (substr($base,1,1) eq 'b') { return 'bb' } }
I'm fairly confident that this would outperform any solution using a hash or a split/join/sort. At least, in assembler. I'm just a little too harried to write code to prove that it might be faster in Perl.
|
|---|