Streamtokenizer

OneGuy oneguyks@gmail.com
Fri May 9 09:49:00 GMT 2008


I was reading

http://www.docjar.com/html/api/java/io/StreamTokenizer.java.html

and it sets nval (i.e number token) with this method.

nval = Double.valueOf(tokbuf.toString()).doubleValue();

This basically creates a String Object from charbuf I guess and parses
the String to number.

Sun's version doesn't create String object and parses the number this way...


		else if ('0' <= c && c <= '9') {
		    v = v * 10 + (c - '0');
		    decexp += seendot;
		} else
		    break;
		c = read();
	    }
	    peekc = c;
	    if (decexp != 0) {
		double denom = 10;
		decexp--;
		while (decexp > 0) {
		    denom *= 10;
		    decexp--;
		}
		/* Do one division of a likely-to-be-more-accurate number */
		v = v / denom;
	    }
	    nval = neg ? -v : v;
	    return ttype = TT_NUMBER;
	}

Perhaps this was the reason why it was 10 times slower in this
benchmark since all sumcol benchmark does is parse huge number of
numbers from Stream and adds the number.



More information about the Java mailing list