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 06/01/2016 07:50 PM, 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?

Each invocation of sscanf counts the number of characters in the input string. For more typical use cases, doing it this way is faster than checking for the null terminator while parsing the input string. In your scenario, this leads to very bad performance.

You could use fmemopen and fscanf to avoid this problem.

Florian


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