in reply to Re^7: Working with fixed length files (Crap benchmark!)
in thread Working with fixed length files

With all sysread's re-placed by read's my bench shows much more reliable figures:

Rate buk ike1 ike2 buk 81.1/s -- -43% -46% ike1 143/s 76% -- -5% ike2 150/s 85% 5% --

I think it would be hard to reduce the overhead even more.

use strict; use warnings; use Benchmark qw(cmpthese); my $data = do { local $/; <DATA> } x 400; my @data; my $rec = chr (0) x 512; { # 1. BrowserUk my @type3l = split m/:/, "02:10:33:15:19:10:3:18:6:4"; my $n = 0; my @type3o = map { $n += $_; $n - $_; } @type3l; my @type3 = map \substr ($rec, $type3o[$_], $type3l[$_]), 0 .. $# +type3o; my @typeOl = split m/:/, "02:98:11:9"; $n = 0; my @typeOo = map { $n += $_; $n - $_; } @typeOl; my @typeO = map \substr ($rec, $typeOo[$_], $typeOl[$_]), 0 .. $# +typeOo; sub buk { open my $fh, "<", \$data; while (read $fh, $rec, 122) { @data = map $$_, @type3; read $fh, $rec, 122; @data = map $$_, @typeO; } } # buk } sub ike2 { open my $fh, "<", \$data; while (read $fh, $rec, 244) { @data = unpack "A2 A10 A33 A15 A19 A10 A3 A18 A6 A4 x2" . "A2 A98 A11 A9 x2", $rec; } } # ike2 sub ike1 { open my $fh, "<", \$data; while (read $fh, $rec, 122) { @data = unpack "A2 A10 A33 A15 A19 A10 A3 A18 A6 A4 x2", $rec; read $fh, $rec, 122; @data = unpack "A2 A98 A11 A9 x2", $rec; } } # ike1 cmpthese (-2, { ike1 => \&ike1, ike2 => \&ike2, buk => \&buk, }); __END__ 03002068454210482 000000004204.572011-04-14 + 19:53:41INTERNET C 750467375 0214833 + G02042954 03002068703214833 000000002558.662011-04-15 + 08:17:19INTERNET C 761212737 0211561 + 05601207284 03002068802911561 000000001463.702011-04-15 + 08:40:52INTERNET C 719807216 029911 + 00100275296

Enjoy, Have FUN! H.Merijn