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
The results of the parse_int microbenchmark are misleading #4662
Comments
I like the improvement described in (1). As for (2), my understanding is that |
This certainly needs to be fixed for 0.2 - especially since the git blame finds me as the author of this! |
I see a 16% improvement in |
Feel free to submit a pull request for a better ltoa implementation. |
I see from your blog, @vitaut, that you've done a lot of work on fast formatting and integer printing in various languages. If you're interested, I think that our routines are respectable, but we always value performance and I'm sure they could use some further tuning since they were originally written. |
The results of the parse_int benchmark microbenchmark reported on http://julialang.org/ are somewhat misleading because the C version used as a baseline is written in an inefficient way. I see at least two obvious problems with the C implementation:
strlen
is unnecessarily called in https://github.com/JuliaLang/julia/blob/master/test/perf/micro/perf.c#L30. Moreover it is called at every iteration! An idiomatic C code for that would be something along the lines of:Note that the code is not only more efficient but also smaller and doesn't contain useless calls to
strlen
.sprintf
which is one of the most inefficient ways to it. In http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html I made a comparison of several methods (I used C++ but the point is true for C as well excluding the methods that usestd::string
). Even a naive implementation of ltoa (https://github.com/vitaut/format-benchmark/blob/master/ltoa.c) is ~70% faster thansprintf
. The reason is thatsprintf
is not an integer to string conversion function, but a general formatting function. So comparing its performance to that of integer to string conversion functions in other languages such ashex
in Python ortoString
in Javascript doesn't make much sense. For instance, the most direct counterpart tosprintf
in Python isstr.format
and nothex
.The text was updated successfully, but these errors were encountered: