Filename | /Users/ap13/perl5/lib/perl5/Number/Compare.pm |
Statements | Executed 8 statements in 252µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 24µs | BEGIN@2 | Number::Compare::
1 | 1 | 1 | 7µs | 30µs | BEGIN@3 | Number::Compare::
1 | 1 | 1 | 7µs | 24µs | BEGIN@4 | Number::Compare::
0 | 0 | 0 | 0s | 0s | new | Number::Compare::
0 | 0 | 0 | 0s | 0s | parse_to_perl | Number::Compare::
0 | 0 | 0 | 0s | 0s | test | Number::Compare::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Number::Compare; | ||||
2 | 2 | 24µs | 2 | 36µs | # spent 24µs (12+12) within Number::Compare::BEGIN@2 which was called:
# once (12µs+12µs) by File::Find::Rule::BEGIN@7 at line 2 # spent 24µs making 1 call to Number::Compare::BEGIN@2
# spent 12µs making 1 call to strict::import |
3 | 2 | 23µs | 2 | 52µs | # spent 30µs (7+22) within Number::Compare::BEGIN@3 which was called:
# once (7µs+22µs) by File::Find::Rule::BEGIN@7 at line 3 # spent 30µs making 1 call to Number::Compare::BEGIN@3
# spent 22µs making 1 call to Exporter::import |
4 | 2 | 202µs | 2 | 41µs | # spent 24µs (7+17) within Number::Compare::BEGIN@4 which was called:
# once (7µs+17µs) by File::Find::Rule::BEGIN@7 at line 4 # spent 24µs making 1 call to Number::Compare::BEGIN@4
# spent 17µs making 1 call to vars::import |
5 | 1 | 600ns | $VERSION = '0.03'; | ||
6 | |||||
7 | sub new { | ||||
8 | my $referent = shift; | ||||
9 | my $class = ref $referent || $referent; | ||||
10 | my $expr = $class->parse_to_perl( shift ); | ||||
11 | |||||
12 | bless eval "sub { \$_[0] $expr }", $class; | ||||
13 | } | ||||
14 | |||||
15 | sub parse_to_perl { | ||||
16 | shift; | ||||
17 | my $test = shift; | ||||
18 | |||||
19 | $test =~ m{^ | ||||
20 | ([<>]=?)? # comparison | ||||
21 | (.*?) # value | ||||
22 | ([kmg]i?)? # magnitude | ||||
23 | $}ix | ||||
24 | or croak "don't understand '$test' as a test"; | ||||
25 | |||||
26 | my $comparison = $1 || '=='; | ||||
27 | my $target = $2; | ||||
28 | my $magnitude = $3 || ''; | ||||
29 | $target *= 1000 if lc $magnitude eq 'k'; | ||||
30 | $target *= 1024 if lc $magnitude eq 'ki'; | ||||
31 | $target *= 1000000 if lc $magnitude eq 'm'; | ||||
32 | $target *= 1024*1024 if lc $magnitude eq 'mi'; | ||||
33 | $target *= 1000000000 if lc $magnitude eq 'g'; | ||||
34 | $target *= 1024*1024*1024 if lc $magnitude eq 'gi'; | ||||
35 | |||||
36 | return "$comparison $target"; | ||||
37 | } | ||||
38 | |||||
39 | sub test { $_[0]->( $_[1] ) } | ||||
40 | |||||
41 | 1 | 3µs | 1; | ||
42 | |||||
43 | __END__ |