| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Data/UUID/LibUUID.pm |
| Statements | Executed 23 statements in 2.61ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.07ms | 3.71ms | Data::UUID::LibUUID::BEGIN@11 |
| 1 | 1 | 1 | 89µs | 107µs | Data::UUID::LibUUID::BEGIN@5 |
| 1 | 1 | 1 | 73µs | 2.31ms | Data::UUID::LibUUID::BEGIN@13 |
| 1 | 1 | 1 | 38µs | 226µs | Data::UUID::LibUUID::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Data::UUID::LibUUID::ascending_ident |
| 0 | 0 | 0 | 0s | 0s | Data::UUID::LibUUID::uuid_to_base64 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | #!/usr/bin/perl | ||||
| 2 | |||||
| 3 | package Data::UUID::LibUUID; | ||||
| 4 | |||||
| 5 | 3 | 140µs | 2 | 125µs | # spent 107µs (89+18) within Data::UUID::LibUUID::BEGIN@5 which was called:
# once (89µs+18µs) by KiokuDB::Role::UUIDs::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/KiokuDB/Role/UUIDs.pm:13] at line 5 # spent 107µs making 1 call to Data::UUID::LibUUID::BEGIN@5
# spent 18µs making 1 call to strict::import |
| 6 | |||||
| 7 | 3 | 131µs | 2 | 413µs | # spent 226µs (38+187) within Data::UUID::LibUUID::BEGIN@7 which was called:
# once (38µs+187µs) by KiokuDB::Role::UUIDs::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/KiokuDB/Role/UUIDs.pm:13] at line 7 # spent 226µs making 1 call to Data::UUID::LibUUID::BEGIN@7
# spent 187µs making 1 call to vars::import |
| 8 | |||||
| 9 | 1 | 4µs | $VERSION = '0.05'; | ||
| 10 | |||||
| 11 | 3 | 515µs | 1 | 3.71ms | # spent 3.71ms (2.07+1.64) within Data::UUID::LibUUID::BEGIN@11 which was called:
# once (2.07ms+1.64ms) by KiokuDB::Role::UUIDs::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/KiokuDB/Role/UUIDs.pm:13] at line 11 # spent 3.71ms making 1 call to Data::UUID::LibUUID::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 2.24ms | # spent 2.31ms (73µs+2.24) within Data::UUID::LibUUID::BEGIN@13 which was called:
# once (73µs+2.24ms) by KiokuDB::Role::UUIDs::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/KiokuDB/Role/UUIDs.pm:13] at line 30 # spent 2.24ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] | ||
| 14 | exports => [qw( | ||||
| 15 | new_uuid_string new_uuid_binary | ||||
| 16 | |||||
| 17 | uuid_to_binary uuid_to_string uuid_to_hex uuid_to_base64 | ||||
| 18 | |||||
| 19 | uuid_eq uuid_compare | ||||
| 20 | |||||
| 21 | new_dce_uuid_string new_dce_uuid_binary | ||||
| 22 | |||||
| 23 | new_uuid_str new_uuid_bin new_dce_uuid_bin new_dce_uuid_str | ||||
| 24 | |||||
| 25 | ascending_ident | ||||
| 26 | )], | ||||
| 27 | groups => { | ||||
| 28 | default => [qw(new_uuid_string new_uuid_binary uuid_eq)], | ||||
| 29 | }, | ||||
| 30 | 3 | 886µs | 1 | 2.31ms | }; # spent 2.31ms making 1 call to Data::UUID::LibUUID::BEGIN@13 |
| 31 | |||||
| 32 | eval { | ||||
| 33 | 1 | 4µs | require XSLoader; | ||
| 34 | 1 | 857µs | 1 | 823µs | XSLoader::load('Data::UUID::LibUUID', $VERSION); # spent 823µs making 1 call to XSLoader::load |
| 35 | 1 | 5µs | 1; | ||
| 36 | 1 | 5µs | } or do { | ||
| 37 | require DynaLoader; | ||||
| 38 | push @ISA, 'DynaLoader'; | ||||
| 39 | bootstrap Data::UUID::LibUUID $VERSION; | ||||
| 40 | }; | ||||
| 41 | |||||
| 42 | # convenient aliases | ||||
| 43 | 1 | 7µs | *new_dce_uuid_bin = \&new_dce_uuid_binary; | ||
| 44 | 1 | 4µs | *new_uuid_bin = \&new_uuid_binary; | ||
| 45 | 1 | 4µs | *new_dce_uuid_str = \&new_dce_uuid_string; | ||
| 46 | 1 | 3µs | *new_uuid_str = \&new_uuid_string; | ||
| 47 | |||||
| 48 | sub uuid_to_base64 { | ||||
| 49 | require MIME::Base64; | ||||
| 50 | MIME::Base64::encode_base64(uuid_to_binary($_[0]), ''); | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | 1 | 4µs | my ( $last_s, $last_us, $i ) = ( 0, 0 ); | ||
| 54 | sub ascending_ident { | ||||
| 55 | my ( $s, $us ) = Time::HiRes::gettimeofday; | ||||
| 56 | |||||
| 57 | # usec is at most 20 bits (log 2 of 1 million), so we truncate the bottom 4 | ||||
| 58 | # and use only 16 bits, with 16 more bits for a counter. decent hardware | ||||
| 59 | # can generate several of these per usec, bot not 65 thousand per 16 usecs =) | ||||
| 60 | |||||
| 61 | # without $i but with a full 20 bits identifiers would be merely | ||||
| 62 | # monotonically increasing | ||||
| 63 | |||||
| 64 | my $trunc_us = $us >> 4; | ||||
| 65 | |||||
| 66 | if ( $last_us != $trunc_us or $last_s != $s ) { | ||||
| 67 | # the timer has increased, we can reset the counter | ||||
| 68 | $i = 0; | ||||
| 69 | $last_us = $trunc_us; | ||||
| 70 | $last_s = $s; | ||||
| 71 | } else { | ||||
| 72 | # increment the timer, but truncate it to 16 bits | ||||
| 73 | |||||
| 74 | # i've never seen it actually bigger than 2 so that gives a margin of | ||||
| 75 | # about 5 orders of magnitude. Hopefully Moore's law doesn't get me ;-) | ||||
| 76 | |||||
| 77 | $i = $i+1 % 0xffff; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | unpack("H*",pack("Nnn", $s, $trunc_us, $i)) . '-' . new_uuid_string(); | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | 1 | 37µs | __PACKAGE__ | ||
| 84 | |||||
| 85 | __END__ |