Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • ... and it is difficult to get it right. On FreeBSD there is usually some whitespace before the line count, so the regexp has to be changed to /^\s*(\d+)/.

    But the results on my system (amd64-freebsd) look different: using a text file with nearly 200000 lines the wc version makes only about 22 iterations/second, much slower than on your system. The the perl version seems to be faster than on your system: 9/s.

  • And now I see the trap: seems to not count the CPU time from child processes! So it's not 3333/s for the wc version, but only 26.9/s.
  • sub tr_count {
        local ( $/, $_ ) = \( 2**19 );
        my $c = 0;
        open my $in, "<", $file;
        $c += y/\n// while <$in>;
        return $c;

    Only slightly slower than wc on my machine.