2 ms·
Assuming arguments will be uniformly picked an extra check would speed things up on many architectures: return (x & 0xFE0000001 == 0) && (x == 6 || x ==
by Someone 7y ago
Assuming arguments will be uniformly picked an extra check would speed things up on many architectures:
return (x & 0xFE0000001 == 0) &&
(x == 6 || x == 28 || x == 496 || x == 8128 || x == 33550336):
The original code does about 5 comparisons in each call. The improvement always does a binary ‘and’ and 1 comparison, and only does the original 5 in 1/256 of the calls.
- contravariant 7y agoAlthough unlike the original code it will be trickier to refactor for >5000 bit architectures once we encounter an odd perfect number.