Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Hash/Merge/Simple.pm |
Statements | Executed 197 statements in 482µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 2 | 2 | 198µs | 198µs | merge (recurses: max depth 2, inclusive time 165µs) | Hash::Merge::Simple::
1 | 1 | 1 | 9µs | 9µs | BEGIN@2 | Hash::Merge::Simple::
1 | 1 | 1 | 8µs | 25µs | BEGIN@7 | Hash::Merge::Simple::
1 | 1 | 1 | 7µs | 10µs | BEGIN@8 | Hash::Merge::Simple::
1 | 1 | 1 | 7µs | 42µs | BEGIN@10 | Hash::Merge::Simple::
0 | 0 | 0 | 0s | 0s | clone_merge | Hash::Merge::Simple::
0 | 0 | 0 | 0s | 0s | dclone_merge | Hash::Merge::Simple::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Hash::Merge::Simple; | ||||
2 | # spent 9µs within Hash::Merge::Simple::BEGIN@2 which was called:
# once (9µs+0s) by Tapper::Config::BEGIN@18 at line 4 | ||||
3 | 1 | 8µs | $Hash::Merge::Simple::VERSION = '0.051'; | ||
4 | 1 | 14µs | 1 | 9µs | } # spent 9µs making 1 call to Hash::Merge::Simple::BEGIN@2 |
5 | # ABSTRACT: Recursively merge two or more hashes, simply | ||||
6 | |||||
7 | 3 | 19µs | 2 | 41µs | # spent 25µs (8+16) within Hash::Merge::Simple::BEGIN@7 which was called:
# once (8µs+16µs) by Tapper::Config::BEGIN@18 at line 7 # spent 25µs making 1 call to Hash::Merge::Simple::BEGIN@7
# spent 16µs making 1 call to warnings::import |
8 | 3 | 20µs | 2 | 13µs | # spent 10µs (7+3) within Hash::Merge::Simple::BEGIN@8 which was called:
# once (7µs+3µs) by Tapper::Config::BEGIN@18 at line 8 # spent 10µs making 1 call to Hash::Merge::Simple::BEGIN@8
# spent 3µs making 1 call to strict::import |
9 | |||||
10 | 3 | 211µs | 2 | 76µs | # spent 42µs (7+34) within Hash::Merge::Simple::BEGIN@10 which was called:
# once (7µs+34µs) by Tapper::Config::BEGIN@18 at line 10 # spent 42µs making 1 call to Hash::Merge::Simple::BEGIN@10
# spent 34µs making 1 call to vars::import |
11 | 1 | 700ns | require Exporter; | ||
12 | 1 | 7µs | @ISA = qw/ Exporter /; | ||
13 | 1 | 1µs | @EXPORT_OK = qw/ merge clone_merge dclone_merge /; | ||
14 | |||||
15 | |||||
16 | # This was stoled from Catalyst::Utils... thanks guys! | ||||
17 | sub merge (@); | ||||
18 | # spent 198µs (198+-0ns) within Hash::Merge::Simple::merge which was called 8 times, avg 25µs/call:
# 7 times (127µs+-127µs) by Hash::Merge::Simple::merge at line 34, avg 0s/call
# once (71µs+127µs) by Tapper::Config::_switch_context at line 75 of Tapper/Config.pm | ||||
19 | 64 | 94µs | shift unless ref $_[0]; # Take care of the case we're called like Hash::Merge::Simple->merge(...) | ||
20 | my ($left, @right) = @_; | ||||
21 | |||||
22 | return $left unless @right; | ||||
23 | |||||
24 | return merge($left, merge(@right)) if @right > 1; | ||||
25 | |||||
26 | my ($right) = @right; | ||||
27 | |||||
28 | my %merge = %$left; | ||||
29 | |||||
30 | for my $key (keys %$right) { | ||||
31 | |||||
32 | 84 | 89µs | my ($hr, $hl) = map { ref $_->{$key} eq 'HASH' } $right, $left; | ||
33 | |||||
34 | 35 | 15µs | 7 | 0s | if ($hr and $hl){ # spent 165µs making 7 calls to Hash::Merge::Simple::merge, avg 24µs/call, recursion: max depth 2, sum of overlapping time 165µs |
35 | $merge{$key} = merge($left->{$key}, $right->{$key}); | ||||
36 | } | ||||
37 | else { | ||||
38 | $merge{$key} = $right->{$key}; | ||||
39 | } | ||||
40 | } | ||||
41 | |||||
42 | return \%merge; | ||||
43 | } | ||||
44 | |||||
45 | |||||
46 | sub clone_merge { | ||||
47 | require Clone; | ||||
48 | my $result = merge @_; | ||||
49 | return Clone::clone( $result ); | ||||
50 | } | ||||
51 | |||||
52 | |||||
53 | sub dclone_merge { | ||||
54 | require Storable; | ||||
55 | my $result = merge @_; | ||||
56 | return Storable::dclone( $result ); | ||||
57 | } | ||||
58 | |||||
59 | |||||
60 | 1 | 4µs | 1; | ||
61 | |||||
62 | __END__ |