This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sscanf ~1000 slower that strtol


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]