Performance exercise: Minimum

1 · Andrey Akinshin · Dec. 20, 2016, midnight
Performance is tricky. Especially, if you are working with very fast operations. In today benchmarking exercise, we will try to measure performance of two simple methods which calculate minimum of two numbers. Sounds easy? Ok, let's do it, here are our guinea pigs for today: int MinTernary(int x, int y) => x < y ? x : y; int MinBitHacks(int x, int y) => x & ((x - y) >> 31) | y & (~(x - y) >> 31); And here are some results: td.slow { color: #ff4444; } td.fast { color: #00C851; } ...