0

Are the basic arithmetic operations same with respect to processor usage. For e.g if I do an addition vs division in a loop, will the calculation time for addition be less than that for division?

I am not sure if this question belongs here or computer science SE

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
WYSIWYG
  • 494
  • 6
  • 23

2 Answers2

0

Yes. Different machine instructions are not equally expensive.

You can either do measurements yourself or use one of the references in this question to help you understand the costs for various instructions.

Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
0

Yes. Here is a quick example:

http://my.safaribooksonline.com/book/hardware/9788131732465/instruction-set-and-instruction-timing-of-8086/app_c

those are the microcode and the timing of the operation of a massively old architecture, the 8086. it is a fairly simple point to start.

of relevant note, they are measured in cycles, or clocks, and everything move at the speed of the cpu (they are synchronized on the main clock or frequency of the microprocessor)

if you scroll down on that table you'll see a division taking anywhere from 80 to 150 cycles.

also note operation speed is affected by which area of memory the operand reside.

note that on modern processor you can have parallel instruction executed concurrently (even if the cpu is single threaded) and some of them are executed out of order, then vector instruction murky the question even more.

i.e. a SSE multiplication can multiply multiple number in a single operation (taking multiple time)

Lorenzo Boccaccia
  • 6,041
  • 2
  • 19
  • 29
  • Thank you. Basically I wanted to know if I have to calculate variance from a dataset should I compute it using the incremental algorithm or calculate sum of squares and get the variance in the end. – WYSIWYG Jun 09 '14 at 08:36
  • http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Incremental_algorithm here, in pseudo code. better working with the incremental one to avid problem with convergence to a solution. – Lorenzo Boccaccia Jun 09 '14 at 08:47