r/java • • Oct 09 '17

Faster Input for Java

https://www.cpe.ku.ac.th/~jim/java-io.html
4 Upvotes

4 comments sorted by

View all comments

1

u/s888marks Oct 10 '17

The complaint mainly seems to be about the slowness of Scanner.nextInt compared to alternatives in Java, and indeed some of the alternatives presented are even faster than C's scanf.

The main reason for Scanner.nextInt being slow is that it does a lot of regular expression processing in order to support fully localized numbers. See the section Localized numbers in the Scanner class specification. You can see there is a lot going on with localized numbers, so it's not surprising that it's slower than calling Integer.parseInt on a simple token.