This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: sscanf ~1000 slower that strtol
- From: Michael Williamson <michael dot h dot williamson at gmail dot com>
- To: Mike Frysinger <vapier at gentoo dot org>, libc-help at sourceware dot org
- Date: Wed, 1 Jun 2016 12:41:32 -0700
- Subject: Re: sscanf ~1000 slower that strtol
- Authentication-results: sourceware.org; auth=none
- References: <CAKZygbcyX4kygLSq_BM9uS7HZYQpyOo6TQQwvLip2QHd-ZoF-g at mail dot gmail dot com> <20160601185348 dot GK7717 at vapier dot lan>
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