The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::ULID::XS - XS backend for ULID generation

SYNOPSIS

use Data::ULID::XS qw(ulid binary_ulid);

# use like Data::ULID

DESCRIPTION

This module replaces some parts of Data::ULID that are performance-critical with XS counterparts. Its interface is the same as Data::ULID, but you get free XS speedups.

FUNCTIONS

Same as Data::ULID. All functions should work exactly the same, but ulid and binary_ulid called with no arguments are reimplemented in XS.

RNG backend

The module uses CryptX to quickly generate secure randomness. The default algorithm used is Sober128. You can change that by replacing the $Data::ULID::XS::RNG variable with a different Crypt::PRNG object.

BENCHMARK

Comparing ULID generation speeds of Perl and XS implementations:

                                 Rate Data::ULID::ulid Data::ULID::binary_ulid Data::ULID::XS::ulid Data::ULID::XS::binary_ulid
Data::ULID::ulid              85339/s               --                    -39%                 -91%                        -93%
Data::ULID::binary_ulid      140302/s              64%                      --                 -85%                        -89%
Data::ULID::XS::ulid         944258/s            1006%                    573%                   --                        -26%
Data::ULID::XS::binary_ulid 1273091/s            1392%                    807%                  35%                          --

Benchmark ran on Thinkpad T480 (i7-8650U) and FreeBSD 14.0.

SEE ALSO

Data::ULID

Types::ULID

AUTHOR

Bartosz Jarzyna, <bbrtj.pro@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) by Bartosz Jarzyna

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.