<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 12/10/2016 12:43 AM, Frank Muller
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAFA6GnDkfsZKtbf6Bgmaxr2FF3Z=LqU0FLGGxP1foNBpZJBwgA@mail.gmail.com"
      type="cite">
      <div>Hi Michael,</div>
      <div><br>
      </div>
      <div>Better, but still ~2 seconds:</div>
      <div><br>
      </div>
      <div><span
          style="font-family:UICTFontTextStyleBody;font-size:17px">>
          timer:tc(fun() -> filelib:fold_files("/usr/share", ".*",
          true, fun(F, N) -> N + 1 end, 0) end).</span><br
          style="font-family:UICTFontTextStyleBody;font-size:17px">
        <span style="font-family:UICTFontTextStyleBody;font-size:17px">{<a
            moz-do-not-send="true" href="tel:1993074,28953" dir="ltr">1993074,28953</a>}</span></div>
      <div><font face="UICTFontTextStyleBody"><span
            style="font-size:17px"><br>
          </span></font></div>
      <div><font face="UICTFontTextStyleBody"><span
            style="font-size:17px">If I get it correctly the call
            matches only on files, not on dirs.</span></font></div>
    </blockquote>
    Yes, the regex only matches on filenames, not directory names. 
    Currently, the filelib:fold_files/5 function requires a regex so you
    are likely paying a penalty for it matching on a wildcard regex on
    each filename.  So, it would probably be nice to have a
    filelib:fold_files/4 that doesn't require a regex.<br>
    <br>
    Best Regards,<br>
    Michael<br>
    <br>
    <blockquote
cite="mid:CAFA6GnDkfsZKtbf6Bgmaxr2FF3Z=LqU0FLGGxP1foNBpZJBwgA@mail.gmail.com"
      type="cite">
      <div><font face="UICTFontTextStyleBody"><span
            style="font-size:17px"><br>
          </span></font></div>
      <div><font face="UICTFontTextStyleBody"><span
            style="font-size:17px">/Frank</span></font></div>
      <div><font face="UICTFontTextStyleBody"><span
            style="font-size:17px"><br>
          </span></font>
        <div class="gmail_quote">
          <div>Le sam. 10 déc. 2016 à 03:12, Michael Truog <<a
              moz-do-not-send="true" href="mailto:mjtruog@gmail.com"><a class="moz-txt-link-abbreviated" href="mailto:mjtruog@gmail.com">mjtruog@gmail.com</a></a>>
            a écrit :<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF" class="gmail_msg"><br>
              <br>
              <div class="m_4764755269035584299moz-cite-prefix
                gmail_msg">On 12/09/2016 03:15 PM, Frank Muller<br>
                <br>
                wrote:<br class="gmail_msg">
                <br>
                <br>
              </div>
              <br>
              <br>
              <blockquote type="cite" class="gmail_msg"><br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg"><br>
                  <br>
                  <div class="gmail_msg">Hi</div>
                  <br>
                  <br>
                  <div class="gmail_msg"><br class="gmail_msg">
                    <br>
                    <br>
                  </div>
                  <br>
                  <br>
                  <div class="gmail_msg">I would like to improve the
                    speed of my directory<br>
                    <br>
                    walker.</div>
                  <br>
                  <br>
                  <div class="gmail_msg"><br class="gmail_msg">
                    <br>
                    <br>
                  </div>
                  <br>
                  <br>
                  <div class="gmail_msg">walk(Dir) -></div>
                  <br>
                  <br>
                  <div class="gmail_msg">    {ok, Files} = prim_<a
                      moz-do-not-send="true"
                      class="m_4764755269035584299moz-txt-link-freetext
                      gmail_msg"><a class="moz-txt-link-freetext" href="file:list_dir(Dir)">file:list_dir(Dir)</a></a>,</div>
                  <br>
                  <br>
                  <div class="gmail_msg">    walk(Dir, Files).</div>
                  <br>
                  <br>
                  <div class="gmail_msg"><br class="gmail_msg">
                    <br>
                    <br>
                  </div>
                  <br>
                  <br>
                  <div class="gmail_msg">walk(Dir, [ Basename | Rest ])
                    -></div>
                  <br>
                  <br>
                  <div class="gmail_msg">    Path = filename:join([ Dir,
                    Basename ]),</div>
                  <br>
                  <br>
                  <div class="gmail_msg">    case filelib:is_dir(Path)
                    of</div>
                  <br>
                  <br>
                  <div class="gmail_msg">        true  -></div>
                  <br>
                  <br>
                  <div class="gmail_msg">            walk(Path);</div>
                  <br>
                  <br>
                  <div class="gmail_msg">        false -></div>
                  <br>
                  <br>
                  <div class="gmail_msg">            io:format("~s~n",
                    [Path]),</div>
                  <br>
                  <br>
                  <div class="gmail_msg">           
                    filelib:file_size(Path)</div>
                  <br>
                  <br>
                  <div class="gmail_msg">    end,</div>
                  <br>
                  <br>
                  <div class="gmail_msg">    walk(Dir, Rest);</div>
                  <br>
                  <br>
                  <div class="gmail_msg">walk(_, []) -></div>
                  <br>
                  <br>
                  <div class="gmail_msg">    ok.</div>
                  <br>
                  <br>
                </div>
                <br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg"><br class="gmail_msg">
                  <br>
                  <br>
                </div>
                <br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg"><br class="gmail_msg">
                  <br>
                  <br>
                </div>
                <br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg">Compared<br>
                  <br>
                  to almost anything i found on the web, it’s still very
                  slow:</div>
                <br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg"><br>
                  <br>
                  <div class="gmail_msg">> timer:tc(fun() ->
                    dir:walk("/usr/share")<br>
                    <br>
                    end).</div>
                  <br>
                  <br>
                </div>
                <br>
                <br>
                <div
                  style="font-family:UICTFontTextStyleBody;font-size:17px"
                  class="gmail_msg">{<a moz-do-not-send="true"
                    href="tel:4662361" class="gmail_msg" target="_blank">4662361</a>,ok}</div>
                <br>
                <br>
              </blockquote>
              <br>
              <br>
              <br class="gmail_msg">
            </div>
            <div text="#000000" bgcolor="#FFFFFF" class="gmail_msg"><br>
              <br>
              Have you tried filelib:fold_files/5<br>
              <br>
              (<a moz-do-not-send="true"
                class="m_4764755269035584299moz-txt-link-freetext
                gmail_msg"
                href="http://erlang.org/doc/man/filelib.html#fold_files-5"
                target="_blank">http://erlang.org/doc/man/filelib.html#fold_files-5</a>)
              ?<br class="gmail_msg">
              <br>
              <br>
              <br class="gmail_msg">
              <br>
              <br>
            </div>
            <br>
            <br>
            <br>
            <br>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>