in reply to Re^6: Fast parsing for cypher block chaining
in thread Fast parsing for cypher block chaining
while is 19% faster! Well, for small files. For big files, it's probably the same speed, but more readable.
use Benchmark qw( cmpthese ); cmpthese(-3, { 'for' => sub { open(my $fh_in, '<', $0) or die("Unable to open input file: $!\n"); my $infile_num_chunks = int((-s $fh_in) / 8); for ($chunk_counter = 0; $chunk_counter < $infile_num_chunks +1; + ++$chunk_counter) { read($fh_in, my $data, 8); # ... } # ... 1; }, 'while' => sub { open(my $fh_in, '<', $0) or die("Unable to open input file: $!\n"); while (read($fh_in, my $data, 8) == 8) { # ... } # ... 1; }, });
Rate for while for 1068/s -- -16% while 1273/s 19% --
|
|---|