That's funny, I was converting yours to Inline::C at the same time.
int cd2(char *number) {
int i, d, total;
total=0;
for (i = 0; i<15; i++) {
d=number[i]-48;
if (!(i & 1)) {
d *=2;
if (d > 9) {d-=9;}
}
total+=d;
}
total *=9;
return total % 10;
}
And, it is a little faster, appreciate it.
$perl ./script
Benchmark: timing 200 iterations of Inline::C (BrowserUK-His Conversion), Inline::C (BrowserUK-My Conversion), Inline::C (orig)...
Inline::C (BrowserUK-His Conversion): 2 wallclock secs ( 2.54 usr + 0.00 sys = 2.54 CPU) @ 78.74/s (n=200)
Inline::C (BrowserUK-My Conversion): 3 wallclock secs ( 2.51 usr + 0.00 sys = 2.51 CPU) @ 79.68/s (n=200)
Inline::C (orig): 3 wallclock secs ( 2.97 usr + 0.00 sys = 2.97 CPU) @ 67.34/s (n=200)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.