| 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.72ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.21ms | 4.02ms | Data::UUID::LibUUID::BEGIN@11 |
| 1 | 1 | 1 | 75µs | 94µs | Data::UUID::LibUUID::BEGIN@5 |
| 1 | 1 | 1 | 73µs | 2.41ms | Data::UUID::LibUUID::BEGIN@13 |
| 1 | 1 | 1 | 36µ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 | 116µs | 2 | 113µs | # spent 94µs (75+19) within Data::UUID::LibUUID::BEGIN@5 which was called:
# once (75µs+19µ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 94µs making 1 call to Data::UUID::LibUUID::BEGIN@5
# spent 19µs making 1 call to strict::import |
| 6 | |||||
| 7 | 3 | 128µs | 2 | 417µs | # spent 226µs (36+190) within Data::UUID::LibUUID::BEGIN@7 which was called:
# once (36µs+190µ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 190µs making 1 call to vars::import |
| 8 | |||||
| 9 | 1 | 4µs | $VERSION = '0.05'; | ||
| 10 | |||||
| 11 | 3 | 649µs | 1 | 4.02ms | # spent 4.02ms (2.21+1.81) within Data::UUID::LibUUID::BEGIN@11 which was called:
# once (2.21ms+1.81ms) 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 4.02ms making 1 call to Data::UUID::LibUUID::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 2.34ms | # spent 2.41ms (73µs+2.34) within Data::UUID::LibUUID::BEGIN@13 which was called:
# once (73µs+2.34ms) 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.34ms 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 | 891µs | 1 | 2.41ms | }; # spent 2.41ms making 1 call to Data::UUID::LibUUID::BEGIN@13 |
| 31 | |||||
| 32 | eval { | ||||
| 33 | 1 | 4µs | require XSLoader; | ||
| 34 | 1 | 861µs | 1 | 831µs | XSLoader::load('Data::UUID::LibUUID', $VERSION); # spent 831µ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 | 6µ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 | 4µ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 | 35µs | __PACKAGE__ | ||
| 84 | |||||
| 85 | __END__ |