Z425

Friday, June 08, 2007

3 orders of magnitude speedup in 10 minutes

It's not often that I can get a 3 orders of magnitude speedup with 10 minutes of work. haha.

I was using a lexer I wrote in one my work projects and it was SLOW. When I wrote the lexer I was using it as an experiment in lolo style lexing (which I will talk about in a future post)..

http://luna2.informatik.uni-osnabrueck.de/alumni/bernd/lolo/

I was just playing around with the concept and did not care about speed. All my little toy datasets were very small, but when I threw a 1.5meg file at it. SMASH. haha.

Ya see.. I was being INCREDIBLY lazy.

I was loading the entire file into a String. When I wanted to eat some characters off the front I did the INCREDIBLY lazy thing of..

this.readerText=this.readerText.subString(eatLength);

OMG is right. haha.

The solution was obvious of course, just pass in an offset and index from that instead. POW! 1000X speedup. haha.

0 Comments:

Post a Comment



<< Home