Explain how cpu time was computed
Question: When a CPU can perform a multiplication in 12 nanoseconds (ns), an addition in 1 ns, and a subtraction in 1.5 ns, which of the following is the minimum CPU time, in nanoseconds, fo开发者_Python百科r the calculation of “a×a – b×b ” ?
Answer: 14.5
I believe it optimizes the equation to (a-b)*(a+b) so it's subtraction + addition + multiplication = 12 + 1 + 1.5 = 14.5.
Though my math isn't the best around so if I'm wrong just comment and don't downvote so I can delete :D
精彩评论