Yes, I think the C version would however be faster by some factor not depending on the input size. That's because Perl has some overhead because of the data structures it uses, because of the garbage collection and so forth. There's also the silly version of comparing a/b < c/d
by multiplying everything with bd
then you reach ad<cb
. Now, are two multiplications
faster than a division
, even if the multiplication is carried out with Karatsuba's algorithm
(the article says that "Karatsuba is usually faster when the multiplicands are longer than 320640 bits" and also gives complexity) or linear time multiplication
? I'm just wondering what the cost of a normal division is in relation to the cost of two multiplications..