In general, if you're careful to not introduce unwanted non-deterministic 
constructions, then performance comes down to the code style that you choose 
and what's in your actions

The scanner construction is super-regular and can indroduce an extra cost 
beyond a single pass because it backtracks. In the best case, the backtracking 
introduces 0 additional cost, yeilding O(n) running time overall. At worst you 
can have O(n^2) running time.
-----Original Message-----
From: Michael Lachmann <lachm...@eva.mpg.de>
Sender: ragel-users-boun...@complang.org
Date: Sat, 3 Nov 2012 23:34:30 
To: <ragel-users@complang.org>
Reply-To: ragel-users@complang.org
Subject: [ragel-users] Hints about ragel for performance

Hi,

I'm starting to learn ragel because I'd like to write a very fast
parser to a fairly simple file structure.
I'd like to learn some of the tricks of increasing the performance of
the resulting program. So,
here are a few questions:

1. Is there a good sample program in terms of performance? I
downloaded awkemu - is that a good example?
2. Often, one can use **, or one can find a terminating character.
    For example, awkemu has:
line = ( blineElements** '\n' )
   I think here just * would have been enough, because there is the
terminating \n - is that right? Does it matter?
Should ** be avoided if possible?

3. Is there a disadvantage of using the lex-like scanner with
\*
pat =>
pat =>
etc., vs just specifying the full machine?
4. Is there a disadvantage of using intersection? For example, I think
the above line handling can written as:
line = something & [^\n]* '\n'
where something doesn't care about handling end-of-line. Is it just as
fast as writing expressions that also handle end-of line?

5. awkemu uses the following:
--
                /* Find the last newline by searching backwards. This is where
                 * we will stop processing on this iteration. */
                p = buf;
                pe = buf + have + len - 1;
                while ( *pe != '\n' && pe >= buf )
                        pe--;
                pe += 1;

                /* fprintf( stderr, "running on: %i\n", pe - p ); */

                %% write exec;

                /* How much is still in the buffer. */
                have = data + len - pe;
                if ( have > 0 )
                        memmove( buf, pe, have );
--
Is the first running backward to find the last eol necessary? It seems
to run part of the file through two parsers.

Thanks!
Michael

_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users
_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to