[mercury-users] a question on efficient parsing of a file

Ralph Becket rafe at csse.unimelb.edu.au
Wed May 19 13:48:42 AEST 2010

Peter Wang, Wednesday, 19 May 2010:
> On 2010-05-19, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> > Vladimir Gubarkov, Tuesday, 18 May 2010:
> > >    And third - it operates over string and current position, and my
> > >    experiments seem to show that this way is not as fast as operating on
> > >    list of chars.
> > 
> > I'm very surprised to hear that.  parsing_utils reads chars directly
> > from the string source, which is just a bounds test and a memory
> > reference (see string.index).  List creation and manipulation is
> > typically much slower.
> On C backends, string.index may incur a strlen() on every call.  You
> should use string.unsafe_index unless you want to rely on loop invariant
> hoisting.

It actually uses unsafe_elem, so no strlen()s.

> Also if the parse_state is as before, you may end up create a new
> structure per character read.  This could be another reason that
> traversing a list is faster -- but that is atypical.

The ps is just an int (the current offset into the string).

-- Ralph
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list