Algorithm-LUHN_XS
view release on metacpan or search on metacpan
This module is an XS version of the original Perl Module
Algorithm::LUHN, which was written by Tim Ayers. It should work exactly
the same, only substantially faster. The supplied check_digit() routine
is 100% compatible with the pure Perl Algorithm::LUHN module, while the
faster check_digit_fast() and really fast check_digit_rff() are not.
How much faster? Here's a benchmark, running on a 3.4GHz i7-2600:
"Benchmark: timing 100 iterations"
"Algorithm::LUHN: 69 secs (69.37 usr 0.00 sys) 1.44/s"
"check_digit: 2 secs ( 1.98 usr 0.00 sys) 50.51/s"
"check_digit_fast: 2 secs ( 1.68 usr 0.00 sys) 59.52/s"
"check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s"
So, it's 35x to 53x faster than the original pure Perl module, depending
on how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs,
with some additions for functions that are new.
This module calculates the Modulus 10 Double Add Double checksum, also
known as the LUHN Formula. This algorithm is used to verify credit card
numbers and Standard & Poor's security identifiers such as CUSIP's and
CSIN's.
You can find plenty of information about the algorithm by searching the
web for "modulus 10 double add double".
FUNCTION
is_valid CHECKSUMMED_NUM
This function takes a credit-card number and returns true if the
number passes the LUHN check.
is_valid_fast CHECKSUMMED_NUM
is_valid_rff CHECKSUMMED_NUM
As with check_digit(), we have 3 versions of is_valid(), each one
progressively faster than the check_digit() that comes in the
original pure Perl Algorithm::LUHN module. Here's a benchmark of 1M
total calls to is_valid():
"Benchmark: timing 100 iterations"
"Algorithm::LUHN: 100 secs (100.29 usr 0.01 sys) 1.00/s"
"is_valid: 3 secs ( 2.46 usr 0.11 sys) 38.91/s"
"is_valid_fast: 2 secs ( 2.38 usr 0.05 sys) 41.15/s"
"is_valid_rff: 2 secs ( 1.97 usr 0.08 sys) 48.78/s"
Algorithm::LUHN_XS varies from 38x to 48x times faster than the
original pure perl Algorithm::LUHN module. The is_valid() routine is
100% compatible with the original, returning either '1' for success
or the empty string '' for failure. The is_valid_fast() routine
returns 1 for success and 0 for failure. Finally, the is_valid_rff()
function also returns 1 for success and 0 for failure, but only
works with numeric input. If you supply any alpha characters, it
will return 0.
number.
Algorithm::Damm implements a different kind of check digit algorithm,
the Damm algorithm <https://en.wikipedia.org/wiki/Damm_algorithm> (Damm,
not Damn).
Math::CheckDigits implements yet another approach to check digits.
Neil Bowers has also written a review of LUHN modules
<http://neilb.org/reviews/luhn.html>, which covers them in more detail
than this section.
REPOSITORY
<https://github.com/krschwab/Algorithm-LUHN_XS>
AUTHOR
This module was written by Kerry Schwab
(http://search.cpan.org/search?author=KSCHWAB).
COPYRIGHT
Copyright (c) 2018 Kerry Schwab. All rights reserved. Derived from
This module is an XS version of the original Perl Module Algorithm::LUHN, which
was written by Tim Ayers. It should work exactly the same, only substantially
faster. The supplied check\_digit() routine is 100% compatible with the pure
Perl Algorithm::LUHN module, while the faster check\_digit\_fast() and really fast
check\_digit\_rff() are not.
How much faster? Here's a benchmark, running on a 3.4GHz i7-2600:
`Benchmark: timing 100 iterations`
`Algorithm::LUHN: 69 secs (69.37 usr 0.00 sys) 1.44/s`
`check_digit: 2 secs ( 1.98 usr 0.00 sys) 50.51/s`
`check_digit_fast: 2 secs ( 1.68 usr 0.00 sys) 59.52/s`
`check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s`
So, it's 35x to 53x faster than the original pure Perl module, depending on
how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs, with some
additions for functions that are new.
This module calculates the Modulus 10 Double Add Double checksum, also known as
the LUHN Formula. This algorithm is used to verify credit card numbers and
Standard & Poor's security identifiers such as CUSIP's and CSIN's.
You can find plenty of information about the algorithm by searching the web for
"modulus 10 double add double".
# FUNCTION
- is\_valid CHECKSUMMED\_NUM
This function takes a credit-card number and returns true if
the number passes the LUHN check.
- is\_valid\_fast CHECKSUMMED\_NUM
- is\_valid\_rff CHECKSUMMED\_NUM
As with check\_digit(), we have 3 versions of is\_valid(), each one progressively
faster than the check\_digit() that comes in the original pure Perl
Algorithm::LUHN module. Here's a benchmark of 1M total calls to is\_valid():
`Benchmark: timing 100 iterations`
`Algorithm::LUHN: 100 secs (100.29 usr 0.01 sys) 1.00/s`
`is_valid: 3 secs ( 2.46 usr 0.11 sys) 38.91/s`
`is_valid_fast: 2 secs ( 2.38 usr 0.05 sys) 41.15/s`
`is_valid_rff: 2 secs ( 1.97 usr 0.08 sys) 48.78/s`
Algorithm::LUHN\_XS varies from 38x to 48x times faster than the original
pure perl Algorithm::LUHN module. The is\_valid() routine is 100% compatible
with the original, returning either '1' for success or the empty string ''
for failure. The is\_valid\_fast() routine returns 1 for success and 0 for
failure. Finally, the is\_valid\_rff() function also returns 1 for success
and 0 for failure, but only works with numeric input. If you supply any
alpha characters, it will return 0.
- check\_digit NUM
against a card number.
[Algorithm::Damm](https://metacpan.org/pod/Algorithm::Damm) implements a different kind of check digit algorithm,
the [Damm algorithm](https://en.wikipedia.org/wiki/Damm_algorithm)
(Damm, not Damn).
[Math::CheckDigits](https://metacpan.org/pod/Math::CheckDigits) implements yet another approach to check digits.
Neil Bowers has also written a
[review of LUHN modules](http://neilb.org/reviews/luhn.html),
which covers them in more detail than this section.
# REPOSITORY
[https://github.com/krschwab/Algorithm-LUHN\_XS](https://github.com/krschwab/Algorithm-LUHN_XS)
# AUTHOR
This module was written by
Kerry Schwab (http://search.cpan.org/search?author=KSCHWAB).
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
This module is an XS version of the original Perl Module Algorithm::LUHN, which
was written by Tim Ayers. It should work exactly the same, only substantially
faster. The supplied check_digit() routine is 100% compatible with the pure
Perl Algorithm::LUHN module, while the faster check_digit_fast() and really fast
check_digit_rff() are not.
How much faster? Here's a benchmark, running on a 3.4GHz i7-2600:
C<Benchmark: timing 100 iterations>
C<Algorithm::LUHN: 69 secs (69.37 usr 0.00 sys) 1.44/s>
C<check_digit: 2 secs ( 1.98 usr 0.00 sys) 50.51/s>
C<check_digit_fast: 2 secs ( 1.68 usr 0.00 sys) 59.52/s>
C<check_digit_rff: 1 secs ( 1.29 usr 0.00 sys) 77.52/s>
So, it's 35x to 53x faster than the original pure Perl module, depending on
how much compatibility with the original module you need.
The rest of the documentation is mostly a copy of the original docs, with some
additions for functions that are new.
This module calculates the Modulus 10 Double Add Double checksum, also known as
the LUHN Formula. This algorithm is used to verify credit card numbers and
Standard & Poor's security identifiers such as CUSIP's and CSIN's.
You can find plenty of information about the algorithm by searching the web for
"modulus 10 double add double".
=head1 FUNCTION
=over 4
=cut
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
=item is_valid_fast CHECKSUMMED_NUM
=cut
=item is_valid_rff CHECKSUMMED_NUM
As with check_digit(), we have 3 versions of is_valid(), each one progressively
faster than the check_digit() that comes in the original pure Perl
Algorithm::LUHN module. Here's a benchmark of 1M total calls to is_valid():
C<Benchmark: timing 100 iterations>
C<Algorithm::LUHN: 100 secs (100.29 usr 0.01 sys) 1.00/s>
C<is_valid: 3 secs ( 2.46 usr 0.11 sys) 38.91/s>
C<is_valid_fast: 2 secs ( 2.38 usr 0.05 sys) 41.15/s>
C<is_valid_rff: 2 secs ( 1.97 usr 0.08 sys) 48.78/s>
Algorithm::LUHN_XS varies from 38x to 48x times faster than the original
pure perl Algorithm::LUHN module. The is_valid() routine is 100% compatible
with the original, returning either '1' for success or the empty string ''
for failure. The is_valid_fast() routine returns 1 for success and 0 for
failure. Finally, the is_valid_rff() function also returns 1 for success
and 0 for failure, but only works with numeric input. If you supply any
alpha characters, it will return 0.
=cut
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
against a card number.
L<Algorithm::Damm> implements a different kind of check digit algorithm,
the L<Damm algorithm|https://en.wikipedia.org/wiki/Damm_algorithm>
(Damm, not Damn).
L<Math::CheckDigits> implements yet another approach to check digits.
Neil Bowers has also written a
L<review of LUHN modules|http://neilb.org/reviews/luhn.html>,
which covers them in more detail than this section.
=head1 REPOSITORY
L<https://github.com/krschwab/Algorithm-LUHN_XS>
=head1 AUTHOR
This module was written by
Kerry Schwab (http://search.cpan.org/search?author=KSCHWAB).
( run in 0.435 second using v1.01-cache-2.11-cpan-39bf76dae61 )