#!/usr/bin/env perl use strict; use warnings; use autodie; use constant { LINES => 20_000, RECORD => 'X' x 100 . "\n", }; use Benchmark 'cmpthese'; open my $fh, '>>', '/dev/null'; my $out; cmpthese 0 => { kcott_by_line => sub { print $fh RECORD for 1 .. LINES; }, kcott_concat => sub { print $fh RECORD x LINES; }, append_per_line => sub { $out = ''; $out .= RECORD for 1 .. LINES; print $fh $out; } } #### Rate kcott_by_line append_per_line kcott_concat kcott_by_line 716/s -- -20% -93% append_per_line 900/s 26% -- -91% kcott_concat 9690/s 1254% 976% --