![]() It means that the next operation in the loop should be started only after the previous operation finished. Today we will try to measure latency of our operations. ![]() ![]() There are many different ways to benchmark division, each of them will show own results. It’s always hard to benchmark tiny methods. Thus, we multiply n by 2^33 / 3 and divide it by 2^33 ( > 33). In our case, 0xAAAAAAAB = RoundUp(2^33 / 3). The basic idea is the following: we should hide the division inside a constant. Which allows replacing “Division by a constant” by “multiplication + bit shift”. However, it includes an integer division which is an expensive operation. The first method ( n / 3) looks very obvious. ![]() Our main goal is to understand which kind of pitfalls we should expect during benchmarkingĪnd why it’s very important to check different environments. How we should write production code, and so on. We will not discuss which JIT or runtime is better, Let’s try to understand why we could have such results. Uint Div3Simple ( uint n ) => n / 3 uint Div3BitHacks ( uint n ) => ( uint )(( n * ( ulong ) 0xAAAAAAAB ) > 33 ) Īs usual, it’s hard to say which method is faster in advanced because the performance depends on the environment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |