use strict; use warnings; use Benchmark 'cmpthese'; use Math::Prime::Util::GMP 'random_bytes'; use IO::Compress::Deflate; sub original { my $buf = random_bytes(32); my $ret = ''; # Negate bits for my $bytes ($buf, ~$buf) { # Reverse bits for my $bits ($bytes, pack('b*', unpack 'B*', $bytes)) { # Reverse nibbles for my $hex (unpack("H*", $bits), unpack("h*", $bits)) { # Reverse hex string for my $str ($hex, scalar reverse $hex) { $ret .= $str . "\n"; # Rotate hex string $ret .= substr($str, $_) . substr($str, 0, $_) . "\n" for 1 .. 63; } } } } $ret; } sub random { ( join "\n", unpack '(H64)*', random_bytes(32768) ) . "\n" } cmpthese -1, { original => \&original, random => \&random, }; print "\n"; my $z = IO::Compress::Deflate->new( \my $s1 ); $z->print( original() ) for 1 .. 1000; $z->close; my $ratio = 100*( length $s1 )/( 65*1024*1000 ); printf "original output compressed to %.1f%%\n", $ratio; $z = IO::Compress::Deflate->new( \my $s2 ); $z->print( random() ) for 1 .. 1000; $z->close; $ratio = 100*( length $s2 )/( 65*1024*1000 ); printf "random output compressed to %.1f%%\n", $ratio;