On 15/09/2014, at 1:34 PM, srean wrote:

> Two questions:
> 
> i) Does Felix de-synchronize C++ I/O from cstdio ? That speed up things quite 
> a bit

No .. but then Felix doesn't use C++ I/O streams. Its all C FILE*.
In any case this program doesn't do much I/O to the console.

> 
> ii) Rather than using the function split, would it be better to use a 
> generator that yields the lines. Felix has readln for that, correct ?

Dunno. I'm looking at the split function .. and I'm not surprised its 
horrendously slow.
Not surprised at all. I could speed this up heaps and heaps!!

  fun rev_split (x:string, d:char): List::list[string] = {
    fun aux (x:string,y:List::list[string]) =>
      match find (x, d) with
      | None => Cons (x, y)
      | Some ?n => aux$ x.[n+1 to], List::Cons (x.[to n],y)
      endmatch
    ;
    return aux$ x, List::Empty[string];
  }

So, ok, this is tail recursive. But it works by chopping off the head substring
and pushing it onto a list, then calls itself on the tail substring. 

Which means .. copying the tail substring. It would be much faster to use
RE2::StringPiece here. That's a pointer and length count into an *existing*
string. No copying. At the end you'd have to copy the list of string pieces
into a list of actual strings.

Alternatively, one could just use the unsafe_cstr function and scan
the underlying array, making the new strings as we go. Or just pass in
the starting location for the rest of the scan (assuming there's a find_from
function that starts looking at a particular location).

So thanks for bringing my attention to this. 

Unfortunately this is unlikely to speed up Ryan's original test case much.

Felix readln calls:

    gen readln: ifile -> string ="::flx::rtl::ioutil::readln($1)";

  string readln (FILE *f) { 
    bool doecho = flx_isstdin(f) && !flx_isatty (f);
    if (doecho)
       return echo_readln(f);
    else
       return raw_readln (f);
  }


  // includes newline if present
  // null string indicates end of file
  string raw_readln (FILE *fi)
  {
    if(fi)
    {
      string x = "";
      char buffer[MYBUFSIZ+1];
      buffer[MYBUFSIZ]='\0';
next:
      bool eof = fgets(buffer, MYBUFSIZ, fi) == 0;
      if(eof) return x;
      x = x + string(buffer);
      if(x[x.size()-1]=='\n') return x;
      goto next;
    }
    else return "";
  }


--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to