Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Faster Luhn Check Digit Calculation?

by kschwab (Vicar)
on Nov 30, 2018 at 18:08 UTC ( [id://1226545]=note: print w/replies, xml ) Need Help??


in reply to Re: Faster Luhn Check Digit Calculation?
in thread Faster Luhn Check Digit Calculation?

Noticible improvement from simplifying what was in Algorithm::LUHN with "use integer"
Benchmark: timing 10 iterations of Algorithm::LUHN, Tweaked Algorithm::LUHN, bdlightner...
Algorithm::LUHN:  6 wallclock secs ( 6.63 usr +  0.00 sys =  6.63 CPU) @  1.51/s (n=10)
Tweaked Algorithm::LUHN:  5 wallclock secs ( 5.25 usr +  0.00 sys =  5.25 CPU) @  1.90/s (n=10)
bdlightner:  8 wallclock secs ( 7.81 usr +  0.00 sys =  7.81 CPU) @  1.28/s (n=10)

# tweaked Algorithm::LUHN with "use integer" and some simplification sub cd3 { use integer; my $total = 0; my $flip = 1; foreach my $c (reverse split //, shift) { $c *= 2 unless $flip = !$flip; while ($c) { $total += $c % 10; $c = $c / 10; } } return (10 - $total % 10) % 10; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226545]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-20 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found