Reputation: 718
Performance wise, which is better:
a. filesizeInMB = filesize / (1024 * 1024)
or
b. filesizeInMB = filesize / 1024 / 1024
Upvotes: 0
Views: 568
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