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