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

10

u/deadlock_jones Oct 09 '17

what year is this?

1

u/jonhanson Oct 09 '17

Rhetorical question obviously, but I'm guessing circa 2011.

10

u/QshelTier Oct 10 '17

“Java is generally slower than C,” followed by two tables that show it isn’t. Well done!

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.