Reputation: 1378
I have a general question regarding the computation cost of operations. Is the most basic Boolean operation cheaper or more expensive in time than the most basic arithmetic operation. In case there are edge cases then consider the stochastic case where you try out different inputs.
UPDATE Just to refine the question slightly, I want to compare the time complexity of addition with the Boolean equals operations. Here is a resource for time complexity: time complexity wiki
Now from what I understand Boolean equals is just multiplication of bit-wise and operations, so that would make it less efficient in general.
I have run this python code locally that confirms it:
from time import time
a = time()
for i in range(1000000):
26 == 25
print(time() - a)
## 0.040122032165527344
a = time()
for i in range(1000000):
26 + 25
print(time() - a)
## 0.031081438064575195
UPDATE slightly changed code above to make the Boolean equals more efficient
Upvotes: 0
Views: 595
Reputation: 106
Practically speaking, comparisons are typically implemented in hardware so the cost would be the same as an arithmetic operation.
https://en.wikipedia.org/wiki/Digital_comparator
Upvotes: 2