sscanf ~1000 slower that strtol
Michael Williamson
michael.h.williamson@gmail.com
Wed Jun 1 19:41:00 GMT 2016
On 6/1/16, Mike Frysinger <vapier@gentoo.org> wrote:
> On 01 Jun 2016 10:50, Michael Williamson wrote:
>> I have a question. I was comparing the speed of reading some ASCII
>> integers by different methods, and I found that using sscanf (with the
>> characters consumed operand (%n)) is ~1000
>> slower than the fastest method, strtol. Why is it so slow?
>>
>> I am using version ldd (Ubuntu EGLIBC 2.15-0ubuntu10.12) 2.15.
>
> that's 4+ years old. can you retest with something less ancient ?
> -mike
>
I got the same results using a newer version, ldd (Ubuntu EGLIBC
2.19-0ubuntu6.9) 2.19.
Florian Weimer's answer explains the extreme discrepancy in speed,
although I think most
people would be surprised that sscanf is implemented this way. (His
answer also illuminated a buffer overrun bug in the program that I
attached, since I had not null-terminated the string buffer.)
-Mike
More information about the Libc-help
mailing list