http://qs321.pair.com?node_id=1226602


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

Unrolling the loop and using Anonymonk's lookup trick extracts another 5%:

int l[] = { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 }; int c_luhn2( char *s ) { int total = 0; total += l[ s[ 0] - '0' ]; total += s[ 1] - '0'; total += l[ s[ 2] - '0' ]; total += s[ 3] - '0'; total += l[ s[ 4] - '0' ]; total += s[ 5] - '0'; total += l[ s[ 6] - '0' ]; total += s[ 7] - '0'; total += l[ s[ 8] - '0' ]; total += s[ 9] - '0'; total += l[ s[10] - '0' ]; total += s[11] - '0'; total += l[ s[12] - '0' ]; total += s[13] - '0'; total += l[ s[14] - '0' ]; total *= 9; return total % 10; }

I doubt there is much fat left in there :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit