Skip to content
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

Issue31optimizeitoa #80

Merged
merged 6 commits into from
Jul 27, 2014
Merged

Issue31optimizeitoa #80

merged 6 commits into from
Jul 27, 2014

Conversation

miloyip
Copy link
Collaborator

@miloyip miloyip commented Jul 24, 2014

Fixes #31 Optimize integer-to-string conversion in GenericWriter

In the beginning, some tests are written in misctest.cpp. And the performance is nearly the same to the other thirdparty implementations. However, it is quite difficult to further develop and optimize, so I created a side project https://github.com/miloyip/itoa-benchmark .

Currently RapidJSON adopt the branchlut implementation. However, it may subject to be changed in future if better algorithm is developed. The API is very simple. It can be replaced by other implementation easily.

Full specialization of Writer for StringBuffer is added. Additional Push() and Pop() member functions are added for StringBuffer in order to prevent memory copying.

PerfTest results are not obvious because the sample JSON do not contain a lot of integers.
https://gist.github.com/miloyip/1326371e39652acf21d5

Before:
[       OK ] RapidJson.Writer_NullStream (676 ms)
[       OK ] RapidJson.Writer_StringBuffer (1144 ms)

After:
[       OK ] RapidJson.Writer_NullStream (638 ms)
[       OK ] RapidJson.Writer_StringBuffer (1098 ms)

However, when just using Writer::WriteXXX(), the results are obvious:

[       OK ] Misc.itoa_Writer_StringBuffer (180 ms)
[       OK ] Misc.itoa_Writer1_StringBuffer (289 ms)
[       OK ] Misc.itoa64_Writer_StringBuffer (247 ms)
[       OK ] Misc.itoa64_Writer1_StringBuffer (705 ms)

Writer is the new implementation. Writer1 is the original naive implementation.

However, these performance tests are not rigorous enough. I would like to create a native json benchmark project in the future.

@miloyip
Copy link
Collaborator Author

miloyip commented Jul 24, 2014

Hum... So the specialization hide an error that is not covered by unit tests.

miloyip added a commit that referenced this pull request Jul 27, 2014
@miloyip miloyip merged commit c4ce48c into master Jul 27, 2014
@miloyip miloyip deleted the issue31optimizeitoa branch August 8, 2014 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize integer-to-string conversion in GenericWriter
2 participants