-
Notifications
You must be signed in to change notification settings - Fork 19
Use lookup table and loop unrolling to optimize integer to ascii convertion #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nvertion. original code was taken from http://www.slideshare.net/andreialexandrescu1/three-optimization-tips-for-c-15708507 benchmark code: unsigned i, addr=123456790; for (i = 0; i != 100000000; ++i) { sprintf(buf, "%u.%u.%u.%u", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); } benchmark result: Execution time (sec) original : 0.23 built : 0.11 Speedup ratio: compare with the result of `original' (greater is better) built : 2.09
|
Thank you for the PR! It looks great. Before merging it to master, I would like to request some modifications.
|
|
@kazuho
And I fixed a bug which cause tests failure on 32bit architecture. (b7cb770) |
|
Thank you for the changes.
It would be great if you could implement them. The reason I ask for them is because I do see performance degradation compared to master on 32-bit architecture. Your proposed optimization should work fine for both 32-bit and 64-bit platforms, and I am hoping that it would be implemented as such. |
|
@kazuho |
Implement _qrintf_(chk|nck)_long_core, _qrintf_long_core, _qrintf_ilog10u32, _qrintf_ilog10ul. Rename _qrintf_(chk|nck)_int_core to _qrintf_(chk|nck)_long_long_core.
|
I've revisited this and I think the performance degradation was removed. |
Use lookup table and loop unrolling to optimize integer to ascii convertion
|
Thank you for the hard work! Merged to master. |
This code is about 2 times faster than original on Haswell for ipv4addr.c.
Original idea of this code was taken from http://www.slideshare.net/andreialexandrescu1/three-optimization-tips-for-c-15708507
Original:
Optimized version: