nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · edit-21 year agotrashmessage-square43fedilinkarrow-up1597arrow-down16
arrow-up1591arrow-down1message-squaretrashnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · edit-21 year agomessage-square43fedilink
minus-squareEinar@lemm.eelinkfedilinkarrow-up11arrow-down4·edit-21 year agoRecently there was a thread trying to declare PHP obsolete. Hard to beat this in efficiency: function is_even($num) { return $num % 2 === 0; } That said, this should work similarly in most languages.
minus-squareTheBlue22@lemmy.blahaj.zonelinkfedilinkarrow-up16·1 year agoExcept maybe in C++ where the makers must have found some bit-fucking method that saves 0.02ms
minus-squarejmcs@discuss.tchncs.delinkfedilinkarrow-up5·1 year agoIf the language you are using uses “real” integers, using a bit mask to get the least significant bit is probably a lot faster - assuming the compiler doesn’t replace the operation for you, in which case it doesn’t matter.
Recently there was a thread trying to declare PHP obsolete.
Hard to beat this in efficiency:
function is_even($num) { return $num % 2 === 0; }
That said, this should work similarly in most languages.
Except maybe in C++ where the makers must have found some bit-fucking method that saves 0.02ms
If the language you are using uses “real” integers, using a bit mask to get the least significant bit is probably a lot faster - assuming the compiler doesn’t replace the operation for you, in which case it doesn’t matter.