You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. For each test range, values within the range were
used as inputs, and __str_base10() was called 10,000,000 times with
these inputs distributed uniformly. Execution time was measured using
the time command. The results show 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
0 commit comments