Re: Streamtokenizer

OneGuy <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.