in reply to Re: Parsing Text into Arrays..
in thread Parsing Text into Arrays..
And by buggy I mean the following: I dont believe that you can consider a parser correct if it accepts something other than the specification it was intended to parse. Ie, I consider a parser to work correctly if and only if it parses a language specification correctly and nothing more.
Anyway heres my analysis of the different solutions. Additional stuff is welcome.
when you feed it erroneous data like: '({({})'Unmatched ( before HERE mark in regex m/\(\{( << HERE \(\{()\}\)/ at C +:\Temp\castaway.pl line 282.
it almost doubles its speed. No great feat I realize considering that it now does about 25 parses a second. :-)value : string | number | array | hash
To quote from Code Complete (28.2 Code Tuning)
A fast program is just as important as a correct one--False! It's hardly ever true that programs need to be fast or small before they need to be correct. Gerald Weinberg tells the story of a programmer who was flown to Detroit to help debug a program that was in trouble. The programmer worked with the team of programmers who had developed the program, and after several days he concluded that the situation was hopeless.
On the flight home, he mulled over the last few days and realized the true problem. By the end of the flight, he had outlined the necessary code. He tested it for several days and was about to return to Detroit when he got a telegram saying the project had been cancelled because the program was impossible to write. He headed back to Detroit anyway and convinced the executives that the project could be completed.
He then had to convince the project's original programmers. They listened to his presentation, and when he'd finished, the creator of the old system asked,
"And how long does your program take?"
"That varies, but about ten seconds per input."
"Aha! But my program takes only one second per input." The veteran leaned back, satisfied that he'd stumped the upstart programmer. The other programmers seemed to agree, but the new programmer wasn't intimidated.
"Yes, but your program doesn't work. If mine doesn't have to work, I can make it run instantly and take up no memory. "
However I have no doubt that with a bit of hacking all of the people involved here can fix their stuff and still have it faster than the P::RD approach, but this is a good example of why proper testing of both positive and negative cases is essential. Its also a good example of why P::RD is a cool tool. You are much more likely to produce a correct (but slow) result with it than without it, and to do so in much less time than with another approach.
A last point about all of this. You are reciving packets over a network connection. So I'm guessing that just the network part takes much longer than even the slowest solution. Thus the network time is going to swamp the parse time by a great deal, and to me would suggest theres no point in optimizing this.
I think having a read of the code complete article is a worthy use of time.
Cheers,
--- demerphq
my friends call me, usually because I'm late....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Parsing Text into Arrays..
by BrowserUk (Patriarch) on Jan 22, 2003 at 19:12 UTC | |
by demerphq (Chancellor) on Jan 24, 2003 at 00:02 UTC | |
by BrowserUk (Patriarch) on Jan 24, 2003 at 00:59 UTC | |
|
Re: Re: Re: Parsing Text into Arrays..
by castaway (Parson) on Jan 22, 2003 at 18:10 UTC | |
|
Re^3: Parsing Text into Arrays..
by pip9ball (Acolyte) on Aug 17, 2011 at 18:20 UTC |