views:

37

answers:

1

Let a, b be two integers with n digits. I am wondering does the computing time of the square of a is shorter than a*b.

Thank you for your help.

+1  A: 

I don't think there's a way to square A without using an IMUL on x86. I could be wrong.

To find out how long something takes, microbenchmark it!

Edit: oh wait, I've got it! a*b takes two memory reads and a*a takes one! So a*a is faster :-).

True answer: there's no reason a*b would be slower unless you have some outside factor influencing things.

Borealid