Acme-CPANModules-UUID

 view release on metacpan or  search on metacpan

lib/Acme/CPANModules/UUID.pm  view on Meta::CPAN


        {
            module => 'UUID::FFI',
            description => <<'MARKDOWN',

This module provides access to libuuid via the FFI interface. It can create v1
as well as v4 (random) UUIDs. Note that Data::UUID (XS-based) is faster this
module (FFI-based).

The benchmark code creates 1000+1 v1 string UUIDs.

MARKDOWN
            bench_code_template => 'UUID::FFI->new_time for 1..1000; UUID::FFI->new_time->as_hex',
            features => {
                is_xs => 1,
                is_pp => 0,
                create_v1 => 1,
                create_v2 => 0,
                create_v3 => 0,
                create_v4 => 1,
                v4_secure_random => 0,
                v4_rfc4122 => 1,
                create_v5 => 0,
            },
        },

        {
            module => 'UUID::Tiny',
            description => <<'MARKDOWN',

This module should be your go-to choice if you cannot use an XS module. It can
create v1, v3, v4 UUIDs. However, the random v4 UUIDs are not cryptographically
secure; if you need cryptographically secure random UUIDs, use <pm:Crypt::Misc>.

The benchmark code creates 1000+1 v1 string UUIDs.

See also: <pm:Types::UUID> which is a type library that uses Data::UUID as the
backend.

MARKDOWN
            bench_code_template => 'UUID::Tiny::create_uuid() for 1..1000; UUID::Tiny::uuid_to_string(UUID::Tiny::create_uuid())',
            features => {
                is_xs => 0,
                is_pp => 1,
                create_v1 => 1,
                create_v2 => 0,
                create_v3 => 1,
                create_v4 => 1,
                v4_secure_random => 0,
                v4_rfc4122 => 1,
                create_v5 => 1,
            },
        },

        {
            module => 'UUID::Random',
            description => <<'MARKDOWN',

This module simply uses 32 calls to Perl's C<rand()> to construct each random
hexadecimal digits of the UUID (v4). Not really recommended, since perl's
default pseudo-random generator is neither cryptographically secure nor has 128
bit of entropy. It also does not produce v4 UUIDs that conform to RFC 4122 (no
encoding of variant & version information).

To create a cryptographically secure random UUIDs, use <pm:Crypt::Misc>.

The benchmark code creates 1000+1 v4 string UUIDs.

MARKDOWN
            bench_code_template => 'UUID::Random::generate() for 1..1000; ; UUID::Random::generate()',
            features => {
                is_xs => 0,
                is_pp => 1,
                create_v1 => 0,
                create_v2 => 0,
                create_v3 => 0,
                create_v4 => 1,
                v4_secure_random => 0,
                v4_rfc4122 => 0,
                create_v5 => 0,
            },
        },

        {
            module => 'UUID::Random::PERLANCAR',
            description => <<'MARKDOWN',

Just another implementation of <pm:UUID::Random>.

The benchmark code creates 1000+1 v4 string UUIDs.

MARKDOWN
            features => {
                is_xs => 0,
                is_pp => 1,
                create_v1 => 0,
                create_v2 => 0,
                create_v3 => 0,
                create_v4 => 1,
                v4_secure_random => 0,
                v4_rfc4122 => 1,
                create_v5 => 0,
            },
            functions => {
                generate => {
                    bench_code_template => 'UUID::Random::PERLANCAR::generate() for 1..1000; UUID::Random::PERLANCAR::generate()',
                },
                generate_rfc => {
                    bench_code_template => 'UUID::Random::PERLANCAR::generate_rfc() for 1..1000; UUID::Random::PERLANCAR::generate_rfc()',
                },
            },
        },

        {
            module => 'UUID::Random::Secure',
            description => <<'MARKDOWN',

Just like <pm:UUID::Random>, except it uses <pm:Math::Random::Secure>'s
`irand()` to produce random numbers.

The benchmark code creates 1000+1 v4 string UUIDs.

lib/Acme/CPANModules/UUID.pm  view on Meta::CPAN

            features => {
                is_xs => 0,
                is_pp => 1,
                create_v1 => 0,
                create_v2 => 0,
                create_v3 => 0,
                create_v4 => 1,
                v4_secure_random => 1,
                v4_rfc4122 => 1,
                create_v5 => 0,
            },
        },

        {
            module => 'UUID',
            description => <<'MARKDOWN',

This module generates DCE-compatible UUIDs, which according to RFC belongs to
the legacy variants.

The benchmark creates 1000+1 random UUIDs.

MARKDOWN
         bench_code_template => 'my $uuid; UUID::generate_random($uuid) for 1..1000; UUID::generate_random($uuid); $uuid',
            features => {
                is_xs => 1,
                is_pp => 0,
                create_v1 => 0,
                create_v2 => 0,
                create_v3 => 0,
                create_v4 => 0,
                v4_secure_random => 0,
                v4_rfc4122 => 0,
                create_v5 => 0,
                create_legacy => 1,
            },
        },

    ],
};

1;
# ABSTRACT: List of modules that can generate immutable universally unique identifier (UUIDs)

__END__

=pod

=encoding UTF-8

=head1 NAME

Acme::CPANModules::UUID - List of modules that can generate immutable universally unique identifier (UUIDs)

=head1 VERSION

This document describes version 0.011 of Acme::CPANModules::UUID (from Perl distribution Acme-CPANModules-UUID), released on 2023-10-30.

=head1 SYNOPSIS

To run benchmark with default option:

 % bencher --cpanmodules-module UUID

To run module startup overhead benchmark:

 % bencher --module-startup --cpanmodules-module UUID

For more options (dump scenario, list/include/exclude/add participants, list/include/exclude/add datasets, etc), see L<bencher> or run C<bencher --help>.

=head1 DESCRIPTION

UUIDs (Universally Unique Identifiers), sometimes also called GUIDs (Globally
Unique Identifiers), are 128-bit numbers that can be used as permanent IDs or
keys in databases. There are several standards that specify UUID, one of which
is RFC 4122 (2005), which we will follow in this document.

UUIDs are canonically represented as 32 hexadecimal digits in the form of:

 xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

There are several variants of UUID. The variant information is encoded using 1-3
bits in the C<N> position. RFC 4122 defines 4 variants (0 to 3), two of which (0
and 3) are for legacy UUIDs, so that leaves variants 1 and 2 as the current
specification.

There are 5 "versions" of UUID for both variants 1 & 2, each might be more
suitable than others in specific cases. The version information is encoded in
the M position. Version 1 (v1) UUIDs are generated from a time and a node ID
(usually the MAC address); version 2 (v2) UUIDs from an identifier (group/user
ID), a time, and a node ID; version 4 (v4) UUIDs from a rando/mpseudo-random
number; version 3 (v3) UUIDs from hashing a namespace using MD5; version 5 (v5)
from hashing a namespace using SHA-1.

L<Data::UUID> should be your first choice, and when you cannot install XS
modules you can use L<UUID::Tiny> instead.

Aside from the modules listed as entries below, there are also:
L<App::UUIDUtils> (containing CLIs to create/check UUID), L<Data::GUID>
(currently just a wrapper for Data::UUID).

=head1 ACME::CPANMODULES ENTRIES

=over

=item L<Data::UUID>

Author: L<RJBS|https://metacpan.org/author/RJBS>

This module creates v1 and v2 UUIDs. Depending on the OS, for MAC address, it
usually uses a hash of hostname instead. This module is XS, so performance is
good. If you cannot use an XS module, try L<UUID::Tiny> instead.

The benchmark code creates 1000+1 v1 string UUIDs.


=item L<UUID::FFI>

Author: L<PLICEASE|https://metacpan.org/author/PLICEASE>

This module provides access to libuuid via the FFI interface. It can create v1
as well as v4 (random) UUIDs. Note that Data::UUID (XS-based) is faster this
module (FFI-based).

The benchmark code creates 1000+1 v1 string UUIDs.


=item L<UUID::Tiny>

Author: L<CAUGUSTIN|https://metacpan.org/author/CAUGUSTIN>

This module should be your go-to choice if you cannot use an XS module. It can
create v1, v3, v4 UUIDs. However, the random v4 UUIDs are not cryptographically
secure; if you need cryptographically secure random UUIDs, use L<Crypt::Misc>.

The benchmark code creates 1000+1 v1 string UUIDs.

See also: L<Types::UUID> which is a type library that uses Data::UUID as the
backend.


=item L<UUID::Random>

Author: L<PERLER|https://metacpan.org/author/PERLER>

This module simply uses 32 calls to Perl's C<rand()> to construct each random
hexadecimal digits of the UUID (v4). Not really recommended, since perl's
default pseudo-random generator is neither cryptographically secure nor has 128
bit of entropy. It also does not produce v4 UUIDs that conform to RFC 4122 (no
encoding of variant & version information).

To create a cryptographically secure random UUIDs, use L<Crypt::Misc>.

The benchmark code creates 1000+1 v4 string UUIDs.


=item L<UUID::Random::PERLANCAR>

Author: L<PERLANCAR|https://metacpan.org/author/PERLANCAR>

Just another implementation of L<UUID::Random>.

The benchmark code creates 1000+1 v4 string UUIDs.


=item L<UUID::Random::Secure>

Author: L<PERLANCAR|https://metacpan.org/author/PERLANCAR>

Just like L<UUID::Random>, except it uses L<Math::Random::Secure>'s
C<irand()> to produce random numbers.

The benchmark code creates 1000+1 v4 string UUIDs.


=item L<Crypt::Misc>

Author: L<MIK|https://metacpan.org/author/MIK>

This module from the L<CryptX> distribution has a function to create and check
v4 UUIDs.

The benchmark code creates 1000+1 v4 string UUIDs.


=item L<UUID>

Author: L<JRM|https://metacpan.org/author/JRM>

This module generates DCE-compatible UUIDs, which according to RFC belongs to
the legacy variants.

The benchmark creates 1000+1 random UUIDs.


=back

=head1 ACME::CPANMODULES FEATURE COMPARISON MATRIX

 +-------------------------+-----------+-----------+-----------+-----------+-----------+-------+-------+----------------+----------------------+---------------+
 | module                  | create_v1 | create_v2 | create_v3 | create_v4 | create_v5 | is_pp | is_xs | v4_rfc4122 *1) | v4_secure_random *2) | create_legacy |
 +-------------------------+-----------+-----------+-----------+-----------+-----------+-------+-------+----------------+----------------------+---------------+
 | Data::UUID              | yes       | yes       | no        | no        | no        | no    | yes   | N/A            | N/A                  | N/A           |
 | UUID::FFI               | yes       | no        | no        | yes       | no        | no    | yes   | yes            | no                   | N/A           |
 | UUID::Tiny              | yes       | no        | yes       | yes       | yes       | yes   | no    | yes            | no                   | N/A           |
 | UUID::Random            | no        | no        | no        | yes       | no        | yes   | no    | no             | no                   | N/A           |
 | UUID::Random::PERLANCAR | no        | no        | no        | yes       | no        | yes   | no    | yes            | no                   | N/A           |
 | UUID::Random::Secure    | no        | no        | no        | yes       | no        | yes   | no    | yes            | yes                  | N/A           |

lib/Acme/CPANModules/UUID.pm  view on Meta::CPAN

 UUID::Random::generate() for 1..1000; ; UUID::Random::generate()



=item * UUID::Random::PERLANCAR::generate (perl_code)

Code template:

 UUID::Random::PERLANCAR::generate() for 1..1000; UUID::Random::PERLANCAR::generate()



=item * UUID::Random::PERLANCAR::generate_rfc (perl_code)

Code template:

 UUID::Random::PERLANCAR::generate_rfc() for 1..1000; UUID::Random::PERLANCAR::generate_rfc()



=item * UUID::Random::Secure::generate (perl_code)

Code template:

 UUID::Random::Secure::generate() for 1..1000; UUID::Random::Secure::generate()



=item * UUID::Random::Secure::generate_rfc (perl_code)

Code template:

 UUID::Random::Secure::generate_rfc() for 1..1000; UUID::Random::Secure::generate_rfc()



=item * Crypt::Misc (perl_code)

Code template:

 Crypt::Misc::random_v4uuid() for 1..1000; Crypt::Misc::random_v4uuid()



=item * UUID (perl_code)

Code template:

 my $uuid; UUID::generate_random($uuid) for 1..1000; UUID::generate_random($uuid); $uuid



=back

=head1 BENCHMARK SAMPLE RESULTS

=head2 Sample benchmark #1

Run on: perl: I<< v5.38.0 >>, CPU: I<< Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores) >>, OS: I<< GNU/Linux Ubuntu version 20.04 >>, OS kernel: I<< Linux version 5.4.0-164-generic >>.

Benchmark command (default options):

 % bencher --cpanmodules-module UUID

Result formatted as table:

 #table1#
 +---------------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
 | participant                           | rate (/s) | time (ms) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
 +---------------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
 | UUID::Random::Secure::generate        |        30 |     30    |                 0.00% |              4218.76% |   0.0013  |      22 |
 | UUID::Random::Secure::generate_rfc    |        40 |     20    |                42.61% |              2928.29% |   0.0003  |      21 |
 | UUID::Random                          |       100 |      9    |               257.90% |              1106.70% |   0.00018 |      20 |
 | UUID::Tiny                            |       100 |      8    |               335.56% |               891.54% |   0.00013 |      20 |
 | UUID                                  |       171 |      5.84 |               481.07% |               643.25% | 1.4e-06   |      21 |
 | Crypt::Misc                           |       296 |      3.37 |               906.43% |               329.12% | 2.6e-06   |      20 |
 | UUID::Random::PERLANCAR::generate_rfc |       520 |      1.9  |              1682.35% |               142.31% | 7.6e-06   |      20 |
 | UUID::Random::PERLANCAR::generate     |       900 |      1    |              2809.14% |                48.45% | 2.5e-05   |      23 |
 | UUID::FFI                             |       870 |      1.2  |              2848.45% |                46.48% | 1.8e-06   |      20 |
 | Data::UUID                            |      1000 |      0.8  |              4218.76% |                 0.00% | 9.3e-06   |      21 |
 +---------------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+


The above result formatted in L<Benchmark.pm|Benchmark> style:

             Rate  URS:g  URS:g_r    U:R   U:T     U   C:M  URP:g_r   U:F  URP:g   D:U 
  URS:g      30/s     --     -33%   -70%  -73%  -80%  -88%     -93%  -96%   -96%  -97% 
  URS:g_r    40/s    50%       --   -55%  -60%  -70%  -83%     -90%  -94%   -95%  -96% 
  U:R       100/s   233%     122%     --  -11%  -35%  -62%     -78%  -86%   -88%  -91% 
  U:T       100/s   275%     150%    12%    --  -27%  -57%     -76%  -85%   -87%  -90% 
  U         171/s   413%     242%    54%   36%    --  -42%     -67%  -79%   -82%  -86% 
  C:M       296/s   790%     493%   167%  137%   73%    --     -43%  -64%   -70%  -76% 
  URP:g_r   520/s  1478%     952%   373%  321%  207%   77%       --  -36%   -47%  -57% 
  U:F       870/s  2400%    1566%   650%  566%  386%  180%      58%    --   -16%  -33% 
  URP:g     900/s  2900%    1900%   800%  700%  484%  237%      89%   19%     --  -19% 
  D:U      1000/s  3650%    2400%  1025%  900%  630%  321%     137%   49%    25%    -- 
 
 Legends:
   C:M: participant=Crypt::Misc
   D:U: participant=Data::UUID
   U: participant=UUID
   U:F: participant=UUID::FFI
   U:R: participant=UUID::Random
   U:T: participant=UUID::Tiny
   URP:g: participant=UUID::Random::PERLANCAR::generate
   URP:g_r: participant=UUID::Random::PERLANCAR::generate_rfc
   URS:g: participant=UUID::Random::Secure::generate
   URS:g_r: participant=UUID::Random::Secure::generate_rfc

=head2 Sample benchmark #2

Benchmark command (benchmarking module startup overhead):

 % bencher --cpanmodules-module UUID --module-startup

Result formatted as table:

 #table2#
 +-------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
 | participant             | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
 +-------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+



( run in 1.278 second using v1.01-cache-2.11-cpan-ceb78f64989 )