Help for this page

Select Code to Download


  1. or download this
    sub tie_file {
      my @lines;
      tie @lines, 'Tie::File', $file or die "$!";
      map {"$_\n"} @lines[-$limit..-1];
    }
    
  2. or download this
    [chmrr@supox chmrr]$ wc -l /var/log/messages
       4442 /var/log/messages
    [chmrr@supox chmrr]$ perl -w tailbm.pl -10 100 /var/log/messages
    ...
         lastn: 12 wallclock secs ( 7.79 usr +  2.63 sys = 10.42 CPU) @ 26
    +.97/s (n=281)
    lastn_getc: 11 wallclock secs ( 8.83 usr +  1.46 sys = 10.29 CPU) @ 28
    +.38/s (n=292)
      tie_file: 11 wallclock secs (10.15 usr +  0.12 sys = 10.27 CPU) @  3
    +.89/s (n=40)
    
  3. or download this
    [chmrr@supox chmrr]$ perl -w tailbm.pl 500 100 /var/log/messages
    Benchmark: timing 500 iterations of backticks, f_rb_obj, f_rb_obj_u, f
    +_rb_tie, f_rb_tie_u, file_tail, grinder, lastn, lastn_getc, tie_file.
    +..
     backticks:  1 wallclock secs ( 0.43 usr  0.16 sys +  0.61 cusr  0.30 
    +csys =  1.50 CPU) @ 847.46/s (n=500)
    ...
         lastn: 19 wallclock secs (14.20 usr +  4.34 sys = 18.54 CPU) @ 26
    +.97/s (n=500)
    lastn_getc: 20 wallclock secs (15.09 usr +  2.64 sys = 17.73 CPU) @ 28
    +.20/s (n=500)
      tie_file: 143 wallclock secs (126.62 usr +  1.81 sys = 128.43 CPU) @
    +  3.89/s (n=500)