[EMAIL PROTECTED] wrote: > It seems to me that the fastest way to solve this > problem would be with a transform, i.e. tr or y, operator. > That way all the computatiomal work could be done by > perl at compile time. It might be interesting to write > a perl script to generate the two strings used by the tr > operator
My test showed the array to be fastest and hash and tr about the same. The hash and array have the initial overhead of creating the table and the tr needs to do the same (but in a prior run so it can be hard-coded to avoid the slow eval). I tried to use the same binary to integer code in all cases to even the overhead of converting from binary data. # My CPU time results: A1=8.82, A2=44.80, A3=6.42, A4=8.45 use strict; use Bit::Vector; my %hash = (); my @array = (); # method one - use a 256 entry hash for (0 .. 255) { my $b = 0; for (my $ii = 0; $ii < 8; $ii++) { if ($_ & (1 << $ii)) { $b |= (0x80 >> $ii); } } $hash{$_} = $b; $array[$_] = $b; } use Benchmark; # create a binary string for data my $bindat = ''; $bindat .= pack 'C', $_ for 0 .. 255; my $bin; my $res; my $count = 10000; my $results = timethese($count, { 'A1' => sub { foreach (0 .. 255) { $bin = unpack 'C', substr $bindat, $_, 1; $res = $hash{$bin}; } }, 'A2' => sub { foreach (0 .. 255) { $res = 0; $bin = unpack 'C', substr $bindat, $_, 1; for (my $ii = 0; $ii < 8; $ii++) { if ($bin & (1 << $ii)) { $res |= (0x80 >> $ii); } } } }, 'A3' => sub { foreach (0 .. 255) { $bin = unpack 'C', substr $bindat, $_, 1; $res = $array[$bin]; } }, 'A4' => sub { foreach (0 .. 255) { $res = unpack 'C', substr $bindat, $_, 1; $res =~ tr/0x00-0xff/\x00\x80\x40\xc0\x20\xa0\x60\xe0\x10\x90\x50\xd0\x30\xb0\x70\xf0\x08\x88\x48\xc8\x28\xa8\x68\xe8\x18\x98\x58\xd8\x38\xb8\x78\xf8\x04\x84\x44\xc4\x24\xa4\x64\xe4\x14\x94\x54\xd4\x34\xb4\x74\xf4\x0c\x8c\x4c\xcc\x2c\xac\x6c\xec\x1c\x9c\x5c\xdc\x3c\xbc\x7c\xfc\x02\x82\x42\xc2\x22\xa2\x62\xe2\x12\x92\x52\xd2\x32\xb2\x72\xf2\x0a\x8a\x4a\xca\x2a\xaa\x6a\xea\x1a\x9a\x5a\xda\x3a\xba\x7a\xfa\x06\x86\x46\xc6\x26\xa6\x66\xe6\x16\x96\x56\xd6\x36\xb6\x76\xf6\x0e\x8e\x4e\xce\x2e\xae\x6e\xee\x1e\x9e\x5e\xde\x3e\xbe\x7e\xfe\x01\x81\x41\xc1\x21\xa1\x61\xe1\x11\x91\x51\xd1\x31\xb1\x71\xf1\x09\x89\x49\xc9\x29\xa9\x69\xe9\x19\x99\x59\xd9\x39\xb9\x79\xf9\x05\x85\x45\xc5\x25\xa5\x65\xe5\x15\x95\x55\xd5\x35\xb5\x75\xf5\x0d\x8d\x4d\xcd\x2d\xad\x6d\xed\x1d\x9d\x5d\xdd\x3d\xbd\x7d\xfd\x03\x83\x43\xc3\x23\xa3\x63\xe3\x13\x93\x53\xd3\x33\xb3\x73\xf3\x0b\x8b\x4b\xcb\x2b\xab\x6b\xeb\x1b\x9b\x5b\xdb\x3b\xbb\x7b\xfb\x07\x87\x47\xc7\x27\xa7\x67\xe7\x17\x97\x57\xd7\x37\xb7\x77\xf7\x0f\x 8f\x4f\xcf\x2f\xaf\x6f\xef\x1f\x9f\x5f\xdf\x3f\xbf\x7f\xff/; } }, }); __END__ -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs