rehamaltamimi / gwtwiki

Automatically exported from code.google.com/p/gwtwiki
0 stars 0 forks source link

Exceptions misuse #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi!

If you do some simple condition checking instead of catching 
IndexOutOfBoundsException/StringIndexOutOfBoundsException, then you can get a 
signifiant speedup.

I'm trying to parse about a 1000 pages of wiki, and I've got 500k+ thrown 
exceptions...

Original issue reported on code.google.com by kazenni...@gmail.com on 14 Nov 2010 at 3:37

GoogleCodeExporter commented 8 years ago
Why do you think you get a speedup?
Is there any paper you know from?
Did you profile it without using exceptions.

Original comment by axelclk@gmail.com on 14 Nov 2010 at 6:08

GoogleCodeExporter commented 8 years ago
I've read about it in Effective Java by Joshua Bloch,(item#57),
also, I did some timing. For example, I've changed the method 
WikipediaScanner.indexOfUntilNoLetter() to the method below and got 25% 
speedup(41.5 sec -> 32.5 sec) on linux/amd64/1.6.22 JVM. The number of thrown 
exceptions downed to 300k+ on the same set of 1000 pages.

protected int indexOfUntilNoLetter(char testChar, int fromIndex) {
    int index = fromIndex;
    char ch;
    while (index < fSource.length) {
        ch = fSource[index++];
        if (ch == testChar) {
            return index - 1;
        }
        if (Character.isLetter(ch)) {
            if (fSource.length <= index) {
                return -1;
            }
            continue;
        }
        return -1;
    }
    return -1;
}

Original comment by kazenni...@gmail.com on 14 Nov 2010 at 6:47

GoogleCodeExporter commented 8 years ago
I can not see a great effect on my testset on a Winddows box.
But you're right the throwing of exceptions should be avoided.
I commited your change here:
http://code.google.com/p/gwtwiki/source/detail?r=2630

Original comment by axelclk@gmail.com on 15 Nov 2010 at 12:38

GoogleCodeExporter commented 8 years ago

Original comment by axelclk@gmail.com on 27 Jan 2012 at 3:45