I recently had to transform the sign of an integer into either -1 or 1
I wonder, is it faster to do it via an if else statement or by doing a calculation?
if else
s == -1 ? -1 : 1
calculation
ceil((s + 1) / 2) * 2 - 1
I know it's quite a simple example but sometimes you need to map larger intervals and, intuitively, it just seems that the math will be faster at lest for the smaller ones.
Also, how is the relative speed affected by the language used (eg. Python vs C).
Thanks
Aucun commentaire:
Enregistrer un commentaire