Visakh Vijayan
Visakh Vijayan

Reputation: 718

Which one is better performance wise?

Performance wise, which is better:

a. filesizeInMB = filesize / (1024 * 1024)

or

b. filesizeInMB = filesize / 1024 / 1024

Upvotes: 0

Views: 568

Answers (1)

dwjbosman
dwjbosman

Reputation: 966

It is often better to avoid division. Thus a would be better.

On the other hand. If your compiler is smart. It could maybe see that dividing by 1024 is equal to a bit shifting operation. In that case b could be even faster.

Upvotes: 1

Related Questions