You might get even better performance if you use a multibyte template character appropriate to your architecture (perhaps, N or Q). With an appropriate bitmask, you could use a bitwise AND (&) on each value and compare it to 0. This would test 4 or 8 bytes at once.
Update:
The basic idea was to replace:
with:@uchar = split(//,$ucrypt);
The list @vals gets the values of each "ord($uchar$i)". You then test for an element that is greater than 127.my @vals = unpack('C*', $ucrypt);
You potentially get better performance by bundling the tests. Since I have a 32 bit architecture, I'd create a 32 bit bitmask to select the high bits of each byte, unpack 4 bytes at a time, and logically AND the result with the mask:
Now, the test fails if any element of @vals is not zero. The potential improvement comes from doing one logical AND and one integer comparison per 4 bytes rather than one integer comparison per 1 byte.my $mask = 0x80808080; ... my @vals = map { $_ & $mask } unpack('N*', $ucrypt);
In reply to Re: RC4 cipher performance
by eye
in thread RC4 cipher performance
by jaiello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |