logoalt Hacker News

majkinetorlast Friday at 2:14 PM2 repliesview on HN

But then, even numbers will have the worst possible performance.


Replies

IncreasePostslast Friday at 4:02 PM

Good point. Have two programs - one checking every even number and returning odd of not even. And then have a program checking every odd number and returning even if not. Then, a simple program to dispatch to either program randomly, so you end up in the long term with good performance for each.

show 2 replies
bobbylarrybobbylast Friday at 7:05 PM

You brought up an important opportunity for optimization. If you know the distribution of your data, it may make more sense to implement it in terms of the odd numbers and leave even numbers as the fallback. It's important to profile with a realistic distribution of data to make sure you're targeting the correct parity of numbers.