This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.pl
executable file
·100 lines (93 loc) · 2.88 KB
/
bench.pl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env perl
use Modern::Perl;
use autodie;
#use Benchmark qw(:all :hireswallclock);
use Benchmark qw(:hireswallclock);
use Benchmark::Forking qw(cmpthese);
my $count = -1;
Benchmark::Forking->enable();
cmpthese ($count,
{
'join (new)' => sub {
my $node="bla";
while (length($node)<56) {
$node = join '', "y", $node;
}
},
'equals (old)' => sub {
my $node="bla";
while (length($node)<56) {
$node = "y$node";
}
},
'dot' => sub {
my $node="bla";
while (length($node)<56) {
$node = 'y' . $node;
}
}
}
);
cmpthese ($count,
{
'regexp (old)' => sub {
my $key="f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa";
my $node="4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa";
my $qname;
if ($node=~/(.*)\Q.$key\E$/) {
$qname = $node;
$node = $1;
}
},
'substr (new)' => sub {
my $key="f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa";
my $node="4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa";
my $qname;
my $index = index($node, $key);
if ($index != -1) {
$qname = $node;
$node = substr($qname, 0, $index-1);
}
}
}
);
cmpthese ($count,
{
'splitreg (old)' => sub {
my $string ="Q\t4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa\tIN\tANY\t-1\t127.0.0.1\n";
chomp $string;
my @arr=split(/[\t ]+/, $string);
},
'splitplain (new)' => sub {
my $string ="Q\t4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f.ip6.arpa\tIN\tANY\t-1\t127.0.0.1\n";
chomp $string;
my @arr=split(/\t/, $string);
}
}
);
cmpthese ($count,
{
'regexp (old)' => sub {
my $str = 'fe80fe80deadbeefcafebabe73311234';
$str =~ s/(.{4})/$1:/g;
chop $str;
} ,
'join (new)' => sub {
my $str = 'fe80fe80deadbeefcafebabe73311234';
$str = join ':', substr($str, 0, 4), substr($str, 4, 4), substr($str, 8, 4), substr($str, 12, 4), substr($str, 16, 4), substr($str, 20, 4), substr($str, 24, 4), substr($str, 28, 4);
}
}
);
cmpthese ($count,
{
'splitjoin (old & new)' => sub {
my $node = '4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f';
$node = join '', reverse split /\./, $node;
},
'regex' => sub {
my $node = '4.a.9.7.b.9.e.f.0.0.0.0.0.0.0.0.f.f.6.5.0.5.2.0.0.0.0.0.0.8.e.f';
$node =~ s/\.//g;
$node = scalar reverse $node;
}
}
);