title: ReasonML performance against imperative vanilla JavaScript
body: <p><strong>Disclaimer:</strong> I am ReasonML beginner.</p>
  
  <p>I have started playing with ReasonML lately and I have noticed a big difference in performance in contrast to vanilla JavaScript. Here's my examples against a simple puzzle solving function (puzzle taken from: <a href="https://adventofcode.com/2015/day/1" rel="nofollow noreferrer">https://adventofcode.com/2015/day/1</a>)</p>
  
  <p><strong>ReasonML</strong></p>
  
  <pre><code>let head = str =&gt;
    switch (str) {
    | "" =&gt; ""
    | _ =&gt; String.sub(str, 0, 1)
    };
  
  let tail = str =&gt;
    switch (str) {
    | "" =&gt; ""
    | _ =&gt; String.sub(str, 1, String.length(str) - 1)
    };
  
  let rec stringToList = str =&gt;
    switch (str) {
    | "" =&gt; []
    | _ =&gt; [[head(str)], tail(str) |&gt; stringToList] |&gt; List.concat
    };
  
  let rec findFloor = code =&gt;
    switch (head(code)) {
    | "" =&gt; 0
    | "(" =&gt; 1 + findFloor(tail(code))
    | ")" =&gt; (-1) + findFloor(tail(code))
    | _ =&gt; 0
    };
  
  let findFloorFold = code =&gt; {
    let calc = (a, b) =&gt;
      switch (b) {
      | "" =&gt; a
      | "(" =&gt; a + 1
      | ")" =&gt; a - 1
      | _ =&gt; a
      };
  
    code |&gt; stringToList |&gt; List.fold_left(calc, 0);
  };
  </code></pre>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>const solve = code =&gt; {
    let level = 0;
    for (let i = 0, l = code.length; i &lt; l; i++) {
      const el = code[i];
      if (el === "(") {
        ++level;
        continue;
      }
      if (el === ")") {
        --level;
        continue;
      }
    }
    return level;
  };
  </code></pre>
  
  <p><strong>Results</strong></p>
  
  <ul>
  <li>JavaScript: <strong>5ms</strong></li>
  <li>ReasonML (recursive): <strong>470ms</strong></li>
  <li>ReasonML (non-recursive): <strong>7185ms</strong></li>
  </ul>
  
  <p>Is this expected or are my ReasonML function implementations too slow? </p>
  
  <p>Thanks in advance for clarifications/suggestions. </p>
  
  <p><em>Admittedly the second solution (non-rec) is slow due to the string to array conversion but this is because in ReasonML string is not represented by a list of chars.</em> </p>