"Fossies" - the Fresh Open Source Software Archive

Member "MIME-Base64-3.16/benchmark-qp" (27 Sep 2020, 937 Bytes) of package /linux/privat/MIME-Base64-3.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 use blib;
    4 
    5 use MIME::QuotedPrint;
    6 use Time::HiRes qw(time);
    7 
    8 my $file = shift || die "Usage: $0 <file> <old> <slurp>\n";
    9 
   10 if (shift) {
   11     *enc = \&MIME::QuotedPrint::old_encode_qp;
   12     *dec = \&MIME::QuotedPrint::old_decode_qp;
   13 }
   14 else {
   15     *enc = \&MIME::QuotedPrint::encode_qp;
   16     *dec = \&MIME::QuotedPrint::decode_qp;
   17 }
   18 
   19 open(FILE, $file) || die "Can't open $file: $!";
   20 1 while <FILE>;  # warmup
   21 close(FILE);
   22 
   23 my $tmp = "/tmp/qp-$$";
   24 die if -e $tmp;
   25 
   26 my $rounds = 100;
   27 
   28 my $before = time;
   29 
   30 undef($/) if shift;
   31 
   32 for (1 .. $rounds) {
   33     open(FILE, $file) || die;
   34     open(TMP, ">$tmp") || die;
   35     while (<FILE>) {
   36     print TMP enc($_);
   37     }
   38     close(TMP) || die;
   39     close(FILE);
   40 }
   41 
   42 print "Real time encode: ", time - $before, "\n";
   43 
   44 $before = time;
   45 
   46 for (1 .. $rounds) {
   47     open(TMP, $tmp) || die;
   48     while (<TMP>) {
   49     my $x = dec($_);
   50     }
   51 }
   52 
   53 print "Real time decode: ", time - $before, "\n";
   54 
   55 unlink($tmp);
   56 
   57