Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize __str_base10() using bitwise operations
Replace the loop-based method for converting integers to base-10 with a more efficient approach using bitwise operations. The new method simulates division and modulus operations by 10 without using multiplication, division, or modulus instructions, leading to improved performance. This optimization reduces the number of branches compared to the original loop-based approach, resulting in fewer conditional checks and a more streamlined execution path. Experimental results demonstrate significant performance improvements with the new method. Timing data, collected by calling __str_base10() 100,000,000 times in a loop across various ranges, shows the following reductions in execution time: | Range | Old | New | |-----------------|--------|--------| | [0, 10) | 0.473s | 0.293s | | [0, 100) | 0.619s | 0.434s | | [0, 1000) | 0.818s | 0.646s | | [0, 10000) | 1.715s | 0.902s | | [0, 100000) | 2.166s | 1.169s | | [0, 1000000) | 2.239s | 1.453s | | [0, 10000000) | 2.359s | 1.773s | | [0, 100000000) | 2.463s | 2.122s | Link: http://web.archive.org/web/20180517023231/http://www.hackersdelight.org/divcMore.pdf
- Loading branch information