Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Although unlike the original code it will be trickier to refactor for >5000 bit architectures once we encounter an odd perfect number.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: