equal
deleted
inserted
replaced
1 #!/usr/bin/perl |
|
2 use 5.010; |
|
3 use strict; |
|
4 use warnings; |
|
5 use Crypt::CBC; |
|
6 use autodie qw(:all); |
|
7 use Benchmark qw(:all); |
|
8 use File::Temp; |
|
9 |
|
10 my $tmp = File::Temp->new(); |
|
11 |
|
12 { |
|
13 open(my $fh, "/dev/urandom"); |
|
14 local $/ = \(my $x = 1024 * 1024); # 1 MiB |
|
15 for (1 .. 4) { |
|
16 print {$tmp} scalar <$fh>; |
|
17 } |
|
18 } |
|
19 |
|
20 sub getbyref { |
|
21 my $ref = shift; |
|
22 local $/ = undef; |
|
23 seek($tmp, 0, 0); |
|
24 $$ref = <$tmp>; |
|
25 } |
|
26 |
|
27 sub getbyval { |
|
28 seek($tmp, 0, 0); |
|
29 local $/ = undef; |
|
30 return <$tmp>; |
|
31 } |
|
32 |
|
33 cmpthese(900 => { |
|
34 byref => sub { my $x; getbyref(\$x); $_ = length($x) }, |
|
35 byval => sub { my $x = getbyval(); $_ = length($x) }, |
|
36 } |
|
37 ); |
|
38 |
|
39 |
|
40 |
|
41 __END__ |
|
42 |
|
43 |
|
44 |
|
45 cmpthese(30 => { |
|
46 'openssl' => sub { openssl($text) }, |
|
47 'perlssl' => sub { perlssl($text) }, |
|
48 } |
|
49 ); |
|
50 |
|
51 cmpthese(30 => { |
|
52 'gzip' => sub { bingzip($text) }, |
|
53 'perlzip' => sub { perlzip($text) }, |
|
54 } |
|
55 ); |
|
56 |
|
57 sub openssl { |
|
58 open(my $out, "|openssl bf -pass env:X -out $tmp") or die; |
|
59 print $out $_[0]; |
|
60 close $out; |
|
61 die $? if $?; |
|
62 } |
|
63 |
|
64 sub perlssl { |
|
65 open(my $out, ">$tmp"); |
|
66 print $out $cipher0->encrypt($_[0]); |
|
67 close $out; |
|
68 } |
|
69 |
|
70 sub perlzip { |
|
71 open(my $out, ">$tmp"); |
|
72 gzip($_[0] => $out); |
|
73 } |
|
74 |
|
75 sub bingzip { |
|
76 open(my $out, "|gzip -1 >$tmp"); |
|
77 print $out $_[0]; |
|
78 close $out; |
|
79 die $? if $? |
|
80 } |
|