#!/usr/bin/perl use strict; use warnings; use Benchmark qw( timethese cmpthese :hireswallclock ); my $count = 1_000_000; my $result = timethese($count, { 'i_sep' => sub { my %heap; while () { i_sep( \%heap, $_) } }, 'i_peers' => sub { my %heap; while () { i_peers(\%heap, $_) } }, 'i_noop' => sub { my %heap; while () { i_noop( \%heap, $_) } }, }); cmpthese($result); sub i_sep { my ($heap, $result) = @_; chomp $result; my $task = $heap->{task}; if ($result eq '----') { # do nothing } else { #print $result, "\n"; } } sub i_peers { my ($heap, $result) = @_; chomp $result; my $task = $heap->{task}; if ($result =~ / ^\s+(\d+) # 6 \s+([\d\.]+) # 192.168.1.156 :(\d+) # :0 \s+\((\w+)\) # (ALL) \[\w+\s+\w+ # [Cibr 1s \(\s*(\w+)\) # (122bps) \^-([\d\+]+) # ^-001+0 \] # ] \[\w+\s+\w+^? # [Cibr 1s \(\s*(\w+)\) # (122bps) _\d+ # _0 \] # ] /x ) { my $peer_id = $1; my %peer = ( Time => $task->{status}->{Time}, peer_id => $peer_id, ip => $2, port => $3, complete => $4, speed => $5, offset => $6, speed_2 => $7, offset_2 => $8, ); $task->{peers}->{$peer_id} = \%peer; } else { #print $result, "\n"; } } sub i_noop { my ($heap, $result) = @_; } __DATA__ Total good pieces 390 (100%) Total archive size 102225004 completed+00000:ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff completed+00024:ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff completed+00048:fc get http://OpenBSD.somedomain.net/announce.php?info_hash=%2b%d9%df%da%0a%14%d4%2 f%cc%b7%0c%af%39%b5%7d%ac%64%4a%05%d1&peer_id=%33%33%c8%98%29%80%d5%70%93%46%75% ae%e2%3f%3b%7d%cb%78%71%4f&key=%ee%58%0f%93%9e%00%11%56&port=6881&uploaded=0&dow nloaded=0&left=0&event=started&compact=1 Interval 1800 3: Server ready... 5: New peer connected 192.168.1.156 Time 1115237207 4 192.168.1.156:6881 (OUT)[Cibr 1s( 20bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 1 Peers, Download 0bps Upload 0bps^M ---- Time 1115237208 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237209 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237210 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237211 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237212 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237213 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237214 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237215 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ---- Time 1115237216 4 192.168.1.156:6881 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 5 192.168.1.156:0 (ALL)[Cibr 1s(122bps)^-001+0][Cibr 1s(122bps)_0] 100% (390 of 390) 2 Peers, Download 0bps Upload 0bps^M ----