| Filename | /Users/ap13/perl5/lib/perl5/Number/Compare.pm |
| Statements | Executed 8 statements in 259µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 12µs | 24µs | Number::Compare::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 32µs | Number::Compare::BEGIN@3 |
| 1 | 1 | 1 | 7µs | 25µs | Number::Compare::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | Number::Compare::new |
| 0 | 0 | 0 | 0s | 0s | Number::Compare::parse_to_perl |
| 0 | 0 | 0 | 0s | 0s | Number::Compare::test |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Number::Compare; | ||||
| 2 | 2 | 25µ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 | 24µs | 2 | 56µs | # spent 32µs (9+24) within Number::Compare::BEGIN@3 which was called:
# once (9µs+24µs) by File::Find::Rule::BEGIN@7 at line 3 # spent 32µs making 1 call to Number::Compare::BEGIN@3
# spent 24µs making 1 call to Exporter::import |
| 4 | 2 | 206µs | 2 | 42µs | # spent 25µs (7+18) within Number::Compare::BEGIN@4 which was called:
# once (7µs+18µs) by File::Find::Rule::BEGIN@7 at line 4 # spent 25µs making 1 call to Number::Compare::BEGIN@4
# spent 18µ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__ |