Now that we have two programs that parse log files, we can start to take a look at how many lines the program parses per second. First we have to make the two programs as similar as possible. In pseudocode it looks likes this.
- Load all modules
- Take the start time using Time::HiRes
- Put the code of the program here
- Set line_count = 0
- Using stdin: loop through all lines
- Parse the line
- Set line_count++
- Find the time difference
- Divide and line_count / time as
n
lines/s
In Perl this looks like:
use Time::HiRes 'gettimeofday', 'tv_interval';
my $start = [gettimeofday];
# Your program
my $line_count = 0;
while (<>) {
# Parse one line using your software
$line_count++;
}
my $diff = tv_interval($start);
printf "%.2f lines/s\n", $line_count / $diff;
Now run the two programs a few times and look at the parsing speed. In my case there was a big difference between the speed of the two programs. I expect a difference in your run as well.