match this pattern, I was able to speed up the elimination of those lines by inserting the following line of code at the beginning of the loop: next unless index ($_, ‘:POP3-Server:’) > 0; (but not before making the mistake of leaving the parentheses out can you see why that was wrong?). This works because the string
OP3-Server: still uniquely identifies the lines we want. We can do more; in general, simple string operations work faster than regular expressions, so we can follow that line of code with these statements instead of the one that originally began the loop: my ($year, $month, $day, $hour, $minute, $second) = unpack “A4A2A2A2A2A2″, $line; my ($user) = $line =~ /:POP3-Server:.*:(.*)/; However, this benchmarks no faster than the previous code. We can use one more piece of information about the line to get an improvement: the last characters before the username are ]:, and they don’t occur anywhere else on the line. Benchmarking this code shows a speed increase of 50% over the alternative: use Benchmark; $line = ; timethese (200000, { ‘unpack’ => q{ my ($year, $month, $day, $hour, $minute, $second) = unpack “A4A2A2A2A2A2″, $line; my $user = substr $line, index ($line, ‘]:’)+2; }, ‘regex’ => q{ my ($year , $month , $day, $hour, $minute, $second, $user) = ($line =~ /(dddd)(dd)(dd)(dd)(dd)(dd):POP3-Server:.*:(.*)/ ); } }); __END__ 20010208001507:POP3-Server:[198.137.241.43]:gwbush Benchmark: timing 200000 iterations of regex, unpack… regex: 15 wallclock secs (15.63 usr + 0.02 sys = 15.65 CPU) unpack: 10 wallclock secs (10.42 usr + 0.00 sys =
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services