title: Is NodeJs faster than Clojure?
body: <p>I just started learning Clojure. One of the first things I noticed is that there are no loops. That's OK, I can recur. So let's look at this function (from Practical Clojure):</p>
  
  <pre><code>(defn add-up
    "Adds up numbers from 1 to n"
    ([n] (add-up n 0 0))
    ([n i sum] 
      (if (&lt; n i)
        sum
        (recur n (+ 1 i) (+ i sum)))))
  </code></pre>
  
  <p>To achieve the same function in Javascript, we use a loop like so:</p>
  
  <pre><code>function addup (n) {
    var sum = 0;
    for(var i = n; i &gt; 0; i--) {
      sum += i;
    }
    return sum;
  }
  </code></pre>
  
  <p>When timed, the results look like:</p>
  
  <pre><code>input size: 10,000,000
  clojure: 818 ms
  nodejs: 160 ms
  
  input size: 55,000,000
  clojure: 4051 ms
  nodejs: 754 ms
  
  input size: 100,000,000
  clojure: 7390 ms
  nodejs: 1351 ms
  </code></pre>
  
  <p>I then proceeded to try the classic fib (after reading <a href="http://www.mikeperham.com/2008/12/13/clojure-vs-ruby/" rel="noreferrer">this</a>):</p>
  
  <p>in clojure:</p>
  
  <pre><code>(defn fib
    "Fib"
    [n]
    (if (&lt;= n 1) 1
        (+ (fib (- n 1)) (fib (- n 2)))))
  </code></pre>
  
  <p>in js:</p>
  
  <pre><code>function fib (n) {
    if (n &lt;= 1) return 1;
    return fib(n-1) + fib(n-2);
  }
  </code></pre>
  
  <p>Again, the performance has quite some difference.</p>
  
  <pre><code>fib of 39
  clojure: 9092 ms
  nodejs: 3484 ms
  
  fib of 40
  clojure: 14728 ms
  nodejs: 5615 ms
  
  fib of 41
  clojure: 23611 ms
  nodejs: 9079 ms
  </code></pre>
  
  <p>Note I'm using (time (fib 40)) in clojure so it's ignoring the bootup time for JVM. These are ran on a MacBook Air (1.86 Ghz Intel Core 2 Duo).</p>
  
  <p>So what's causing Clojure to be slow here? And why do people say that "Clojure is fast"?</p>
  
  <p>Thanks in advance and Please, no flame wars.</p>